C# winform 解决win7环境下鼠标滚轮无法操作panel滚动条的问题
程序员文章站
2022-05-06 08:02:03
...
帮助类代码如下:
class PanelScrollHelper
{
/// <summary>
/// 初始化Panel
/// </summary>
/// <param name="panel"></param>
public static void InitializePanelScroll(Panel panel)
{
panel.Click += (obj, arg) => { panel.Select(); };
InitializePanelScroll(panel, panel);
return;
}
/// <summary>
/// 递归初始化Panel内部各容器和控件
/// </summary>
/// <param name="container"></param>
/// <param name="panelRoot"></param>
private static void InitializePanelScroll(Control container, Control panelRoot)
{
foreach (Control control in container.Controls)
{
if (control is Panel || control is GroupBox || control is SplitContainer ||
control is TabControl || control is UserControl)
{
control.Click += (obj, arg) => { panelRoot.Select(); };
InitializePanelScroll(control, panelRoot);
}
else if (control is Label)
{
control.Click += (obj, arg) => { panelRoot.Select(); };
}
}
}
}
帮助类调用:
PanelScrollHelper.InitializePanelScroll(panel1);
上一篇: C# Winform应用程序占用内存较大解决方法整理
下一篇: 2020-08-21