WPF 点击按钮滚动视图器

4
我有一个问题,我的菜单在Stackpanel中,而Stackpanel又在ScrollViewer中。即使水平滚动条被隐藏,也可以水平滚动。主要问题是,我无法为按钮创建点击事件。似乎我的滚动事件阻止了下面的某些内容。

enter image description here

XAML 代码

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="200"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="110"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="100"/>
    </Grid.RowDefinitions>
    <Rectangle x:Name="rectangel1" Grid.RowSpan="3">
        <Rectangle.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF0036A0" Offset="0.003"/>
                <GradientStop Color="#FFE9EDFF" Offset="1"/>
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
    <Grid Grid.Column="1" Grid.ColumnSpan="2">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="750"/>
            <ColumnDefinition Width="20"/>
        </Grid.ColumnDefinitions>
        <ScrollViewer x:Name="scrollviewer1" Grid.Column="1" Grid.ColumnSpan="2" 
            HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled"
            PanningMode="HorizontalOnly"
            MouseUp="UIElement_OnMouseUp"
            PreviewMouseLeftButtonDown="UIElement_OnPreviewMouseLeftButtonDown"
            PreviewMouseMove="UIElement_OnPreviewMouseMove" Cursor="Hand">

            <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.ColumnSpan="1">
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle x:Name="btn1" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="No Btn 1" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle x:Name="btn2" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="No Btn 2" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <!--<Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle x:Name="btn3" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Station 3" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>-->
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Button x:Name="btn3" Content="Station 3" Click="btn3_Click" Style="{DynamicResource ButtonStyle1}" >
                        <Button.Resources>
                            <Style x:Key="ButtonFocusVisual">
                                <Setter Property="Control.Template">
                                    <Setter.Value>
                                        <ControlTemplate>
                                            <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
                                <GradientStop Color="#F3F3F3" Offset="0"/>
                                <GradientStop Color="#EBEBEB" Offset="0.5"/>
                                <GradientStop Color="#DDDDDD" Offset="0.5"/>
                                <GradientStop Color="#CDCDCD" Offset="1"/>
                            </LinearGradientBrush>
                            <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
                            <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
                                <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
                                <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
                                <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
                                <Setter Property="BorderThickness" Value="1"/>
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                                <Setter Property="Padding" Value="1"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type Button}">
                                            <Grid>
                                                <Rectangle Fill="#FFFFA6A6" RadiusY="10" RadiusX="10"/>
                                                <Label x:Name="label" Content="BUTTON" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                                            </Grid>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsKeyboardFocused" Value="true"/>
                                                <Trigger Property="ToggleButton.IsChecked" Value="true"/>
                                                <Trigger Property="IsEnabled" Value="false">
                                                    <Setter Property="Foreground" Value="#ADADAD"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Button.Resources>
                    </Button>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle x:Name="btn4" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="No Btn 4" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle x:Name="btn5" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="No Btn 5" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle x:Name="btn6" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="No Btn 6" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle x:Name="btn7" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="No Btn 7" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle x:Name="btn8" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="No Btn 8" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,50,10">
                    <Button x:Name="btn9" Content="Station 9" Click="btn9_Click" Style="{DynamicResource ButtonStyle1}" >
                        <Button.Resources>
                            <Style x:Key="ButtonFocusVisual">
                                <Setter Property="Control.Template">
                                    <Setter.Value>
                                        <ControlTemplate>
                                            <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
                                <GradientStop Color="#F3F3F3" Offset="0"/>
                                <GradientStop Color="#EBEBEB" Offset="0.5"/>
                                <GradientStop Color="#DDDDDD" Offset="0.5"/>
                                <GradientStop Color="#CDCDCD" Offset="1"/>
                            </LinearGradientBrush>
                            <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
                            <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
                                <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
                                <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
                                <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
                                <Setter Property="BorderThickness" Value="1"/>
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                                <Setter Property="Padding" Value="1"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type Button}">
                                            <Grid>
                                                <Rectangle Fill="#FFFFA6A6" RadiusY="10" RadiusX="10"/>
                                                <Label x:Name="label" Content="Button 9" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                                            </Grid>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsKeyboardFocused" Value="true"/>
                                                <Trigger Property="ToggleButton.IsChecked" Value="true"/>
                                                <Trigger Property="IsEnabled" Value="false">
                                                    <Setter Property="Foreground" Value="#ADADAD"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Button.Resources>
                    </Button>
                </Grid>
            </StackPanel>

        </ScrollViewer>

        <Rectangle x:Name="rectlinks" Grid.Column="0" Fill="#FFFF7676" MouseEnter="rectlinks_MouseEnter" />
        <Rectangle x:Name="rectrechts" Grid.Column="2" MouseEnter="rectrechts_MouseEnter" Fill="#FFFF7474"  />
    </Grid>
    <Label x:Name="label1" Content="Wert"/>
    <Label x:Name="label2" Content="mehr" Margin="0,50,0,0"/>


</Grid>

这是C#代码

using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace ScrollMenue
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private double hOff;

        public MainWindow()
        {
            InitializeComponent();



        }



        private void rectrechts_MouseEnter(object sender, MouseEventArgs e)
        {
            label1.Content = "rechts";
            scrollviewer1.LineRight();
        }

        private void rectlinks_MouseEnter(object sender, MouseEventArgs e)
        {

            if (rectlinks.IsMouseOver == true)
            {
                scrollviewer1.ScrollToHorizontalOffset(scrollviewer1.HorizontalOffset + 10);
                label1.Content = "links";
                scrollviewer1.LineLeft();
            }
        }


        private Point scrollMousePoint;

        private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            scrollviewer1.ReleaseMouseCapture();
        }

        private void UIElement_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            scrollviewer1.CaptureMouse();
            scrollMousePoint = e.GetPosition(scrollviewer1);
            hOff = scrollviewer1.HorizontalOffset;
        }

        private void UIElement_OnPreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (scrollviewer1.IsMouseCaptured)
            {
                scrollviewer1.ScrollToHorizontalOffset(hOff + (scrollMousePoint.X - e.GetPosition(scrollviewer1).X));
            }
        }

        private void btn9_Click(object sender, RoutedEventArgs e)
        {
            label2.Content = "Click";
        }

        private void btn3_Click(object sender, RoutedEventArgs e)
        {
            label2.Content = "Click";
        }
    }
}

你的Xaml代码很混乱,能否通过删除与你特定问题无关的内容来简化它?顺便问一下,你为什么认为ScrollViewer与点击事件有关系? - 3615
@3615,他的滚动视图与点击事件相关,因为他通过按下鼠标按钮来滚动。我喜欢他有所有的代码,因为我可以将它粘贴到我的VS中并运行它。 - JohnChris
1
@JohnChris 我同意问题必须是完整和可验证的,但它也必须是“最小化”的,正如如何创建一个最小化、完整和可验证的示例所述。 - 3615
好的,很公正,我会点赞你的评论,因为这是我第一次看到那个链接,谢谢 :) - JohnChris
2个回答

1

现在我找到了想要的解决方案,得益于 JohnChris 和另一位优秀的程序员的帮助:D 感谢大家:D

必须向项目添加一个引用,UIAutomationProvider.dll,并添加两个 using 语句:using System.Windows.Automation.Peers 和 System.Windows.Automation.Provider,这些允许使用 Invoke Provider 和 Peers。

XAML 代码:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="200"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="110"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="100"/>
    </Grid.RowDefinitions>
    <Rectangle Name="rectangel1" Grid.RowSpan="3">
        <Rectangle.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF0036A0" Offset="0.003"/>
                <GradientStop Color="#FFE9EDFF" Offset="1"/>
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
    <Grid Grid.Column="1" Grid.ColumnSpan="2">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="750"/>
            <ColumnDefinition Width="20"/>
        </Grid.ColumnDefinitions>
        <ScrollViewer Name="scrollviewer1" Grid.Column="1" Grid.ColumnSpan="2" 
                      HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled"
                      PanningMode="HorizontalOnly"
                      MouseUp="UIElement_OnMouseUp"
                      PreviewMouseLeftButtonDown="UIElement_OnPreviewMouseLeftButtonDown"
                      PreviewMouseMove="UIElement_OnPreviewMouseMove"
                      >

            <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.ColumnSpan="1">
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn1" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Station 1" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn2" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Station 2" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn3" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <!--<Label Content="Station 3" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>-->
                    <Button Name="BtnFoo" Click="ButtonBase_OnClick">Foo!</Button>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn4" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Station 4" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn5" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Station 5" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn6" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Station 6" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn7" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Station 7" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,50,10">
                    <Rectangle Name="btn8" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Station 8" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
            </StackPanel>

    </ScrollViewer>

    <Rectangle Name="rectlinks" Grid.Column="0" Fill="#FFFF7676" MouseEnter="rectlinks_MouseEnter" />
    <Rectangle Name="rectrechts" Grid.Column="2" MouseEnter="rectrechts_MouseEnter" Fill="#FFFF7474"  />
</Grid>
<Label Name="label1" Content="Wert"/>
    <Label Name="label2" Content="mehr" Margin="0,50,0,0"/>


</Grid>

C#代码:

namespace ScrollMenue
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private double hOff;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void rectrechts_MouseEnter(object sender, MouseEventArgs e)
        {
            //label1.Content = "rechts";
            //scrollviewer1.LineRight();
        }

        private void rectlinks_MouseEnter(object sender, MouseEventArgs e)
        {

            //if (rectlinks.IsMouseOver == true)
            //{
            //    scrollviewer1.ScrollToHorizontalOffset(scrollviewer1.HorizontalOffset + 10);
            //    label1.Content = "links";
            //    scrollviewer1.LineLeft();
            //}
        }


        private Point scrollMousePoint;
        private bool drag;

        private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            scrollviewer1.ReleaseMouseCapture();

            if (IsMouseOverControl(BtnFoo) && !drag)
            {
                var peer = new ButtonAutomationPeer(BtnFoo);
                var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;

                invokeProv?.Invoke();
            }

            drag = false;
        }

        private void UIElement_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

            scrollMousePoint = e.GetPosition(scrollviewer1);
            hOff = scrollviewer1.HorizontalOffset;

            drag = false;
            scrollviewer1.CaptureMouse();
        }

        private void UIElement_OnPreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (scrollviewer1.IsMouseCaptured)
            {
                var moveTo =  scrollMousePoint.X - e.GetPosition(scrollviewer1).X;

                if (Math.Abs(moveTo ) > 1)
                {
                    drag = true;
                    scrollviewer1.ScrollToHorizontalOffset(hOff + moveTo);
                }


            }
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
           MessageBox.Show("Click");
        }

        private bool IsMouseOverControl(UIElement control)
        {
            var mousePos = Mouse.GetPosition(control);
            var size = control.RenderSize;

            if (mousePos.X < 0 || mousePos.X > size.Width ||
                mousePos.Y < 0 || mousePos.Y > size.Height)
            {
                return false;
            }

            return true;
        }
    }
}

这是一个很棒的解决方案,比我的技能要高级一些,所以我将研究所有这些新事物,谢谢(点赞)。 - JohnChris

0

我找到了你的解决方案,

我只是针对一个按钮进行了操作,但你可以对所有按钮进行操作,

 private void UIElement_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (e.Source == btn3)
        {  btn3_Click(sender, e); }

        scrollMousePoint = e.GetPosition(scrollviewer1);
        hOff = scrollviewer1.HorizontalOffset;
        scrollviewer1.CaptureMouse();
    }

  private void btn9_Click(object sender, RoutedEventArgs e)
    {
        label2.Content = "i AM WORKING"; //You can press and still scroll
    }

更新:

从您的评论中可以看出,您现在希望在触摸按钮时不触发它,因为您可能只想滚动,您需要实现某种逻辑,例如保持手势,这里有一篇文章介绍了如何实现:

WPF是否具有触摸和保持手势?

更新2:

太棒了,我做到了,而且解决方案非常简单,

在XAML中添加另一个PreviewMouseLeftButtonUp处理程序,然后在代码后台(C#)中执行以下操作:

     private DateTime mouseTimer;
    private void UIElement_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        mouseTimer = DateTime.Now;
        scrollviewer1.CaptureMouse();
        scrollMousePoint = e.GetPosition(scrollviewer1);
        hOff = scrollviewer1.HorizontalOffset;

    }

    private void scrollviewer1_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        TimeSpan difference = DateTime.Now - mouseTimer;

        if (difference.TotalSeconds < 1)
        {
            btn3_Click(sender, e);
        }
        else
            return;

    }

现在,如果是点击,它会打开,但如果你按住点击,它只会滚动,日期时间的使用非常棒。


嗨JohnChris,你的示例很好,但是它没有解决问题,因为当你开始滚动Scrollviewer时,如果你在按钮上方,它会占用点击事件,这样你就无法滚动了:D我认为还有一点要做。 - PCode
@PCode,移除消息框并添加标签更新即可。这样,您可以单击按钮更新标签内容,并仍然可以滚动。我已更新我的答案以显示标签,我已尝试过它,它可以更新,您可以单击按钮和滚动。 - JohnChris
你的示例能夠運作,但首先它應該接收拖動(滾動)事件...在你的示例中,它會接收點擊和滾動事件,這很好,但這不是我所需要的,因為當我的按鈕事件打開另一個視圖或用戶控件時,它會將其打開,但我無法在菜單中向下滾動到(例如)第23個按鈕:D你知道我的意思嗎?如果我想要滾回到第23個按鈕(例如),並且我想通過使用滑鼠按鈕在第3個按鈕上開始滾動,它會先調用第3個按鈕的事件,然後再滾動,但當第3個按鈕在窗口之間切換時,我會離開ScrollView。 - PCode
@PCode,如果你想要实现这个功能,你需要考虑使用什么逻辑。你想让按钮双击打开吗?你想设置时间延迟(例如,如果你按住按钮超过2秒钟它会打开)吗?希望这可以帮到你——但是,原始问题已经得到了回答... :p - JohnChris
是的,JohnChris,我认为这很酷。如果我按住我的左鼠标键超过一秒钟或者直接在滚动视图中移动鼠标,我只能滚动,否则我可以点击。就像安卓手机上的滚动菜单一样,当您将选项菜单向下拖动时,您可以滚动选择“wifi、蓝牙”等图标。:D 这也不会在我滚动并且在滚动区域超过一秒钟时进行鼠标单击:D顺便说一句,感谢您的帮助:D - PCode
@PCode。没问题,像这样的解决方案应该已经存在了,因为它在手机中是常见功能。我在答案中提供的链接,我还没有尝试过,只是提供信息而已——但我认为我找到了更容易的方法,很快就会更新。 - JohnChris

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接