1. RichTextBox u2 = new RichTextBox();
2. 先记住日RichTextBox没有显示滚动条时的总宽度和显示宽度
u2.Width - u2.ClientSize.Width。
3. 当显示垂直滚动条时,显示宽度会变化。
当RichTextBox没有显示垂直滚动条时,在RichTextBox中滚动鼠标时,滚动的是父窗口的滚动条。
private void U2_MouseWheel(object sender, MouseEventArgs e)
{
int size = u2.Width - u2.ClientSize.Width;
Console.WriteLine(panel1.VerticalScroll.Value);
if (size <= _size)
{
int delta = 120;
int value = 0;
if (e.Delta > 0)
{
value= Math.Max(panel1.VerticalScroll.Minimum, panel1.VerticalScroll.Value - delta);
}
else
{
value = Math.Min(panel1.VerticalScroll.Maximum, panel1.VerticalScroll.Value + delta);
}
panel1.VerticalScroll.Value = value;
panel1.VerticalScroll.Value = value;
}
}
这里贴出主要代码,demo下载路径:
http://download.csdn.net/detail/nkhuangyanping/9846939