相关疑难解决方法(0)

使用任何带有滚动条的控件时,不会触发MouseWheel事件(在C#Windows窗体中)

当我使用带有滚动条的任何控件(ListBox,Panel,TextBox)时,MouseWheel事件不会触发.

重现问题:

public class Form1 : Form
 {
  private readonly Button button1;
  private readonly TextBox textBox1;

  private void button1_MouseWheel(object sender, MouseEventArgs e)
  {
   ToString(); // doesn't fire when uncomment lines below
  }

  public Form1()
  {
   button1 = new Button();
   textBox1 = new TextBox();
   SuspendLayout();

   button1.Location = new System.Drawing.Point(80, 105);
   button1.Size = new System.Drawing.Size(75, 23);
   button1.MouseWheel += button1_MouseWheel;
   button1.Click += button1_Click;

   textBox1.Location = new System.Drawing.Point(338, 105);
   //textBox1.Multiline = true; // uncomment this
   //textBox1.ScrollBars = ScrollBars.Vertical;  // uncomment this 
   textBox1.Size = new …
Run Code Online (Sandbox Code Playgroud)

c# events scrollbar mousewheel winforms

13
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×1

events ×1

mousewheel ×1

scrollbar ×1

winforms ×1