【问题标题】:How to make touchlike scroll in winforms for a panel?如何在面板的winforms中进行触摸式滚动?
【发布时间】:2021-07-17 01:21:39
【问题描述】:

因为这里已经问过并回答了 how to get smartphone like scrolling for a winforms touchscreen app ( scrolling panel )

我的解决方案有问题。它仅在我直接单击面板并滚动时才有效。如果我到处都有标签/文本框之类的元素,它就不起作用。我需要在元素之间单击,所以我直接触摸面板。那么我现在将如何解决这个问题?在面板内的所有元素上添加鼠标移动/向下方法?

【问题讨论】:

标签: c# winforms


【解决方案1】:

对所有面板内控件的主面板使用相同的事件。

panel1.MouseDown += innerpanel_MouseDown;
panel1.MouseMove += innerpanel_MouseMove;
panel1.MouseUp += innerpanel_MouseUp;
foreach(Control ctr in panel1.Controls)
{
    ctr.MouseDown += innerpanel_MouseDown;
    ctr.MouseMove += innerpanel_MouseMove;
    ctr.MouseUp += innerpanel_MouseUp;
}

活动

private void innerpanel_MouseDown(object sender, MouseEventArgs e)
{
    //implementation
    Control ctr = (Control)sender;
    MessageBox.Show(ctr.Name);
}
private void innerpanel_MouseMove(object sender, MouseEventArgs e)
{
   //implementation
}
private void innerpanel_MouseUP(object sender, MouseEventArgs e)
{
  //implementation
}

请记住,如果您在控制面板中有一个按钮,则该按钮单击事件将运行,并且任何具有单击事件的控件都将运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-30
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多