C#中给滚动条增加鼠标滚动轮控制事件
当滚动条的父控件获得焦点时,可以使用鼠标的滚动轮来控制滚动条
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.richTextBox1.MouseWheel += new System.Windows.Forms.MouseEventHandler(richTextBox1_MouseWheel);
}
void richTextBox1_MouseWheel(object sender, MouseEventArgs e)
{
this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y + e.Delta);
}
}
以上是上下卷动,要想左右卷动,可修改为以下代码:
new System.Drawing.Point(this.Location.X + e.Delta, this.Location.Y);