C# Form 滚动(scroll)问题
我的C#WinForm里面有一个richtextbox,当焦点在这个richtextbox的时候,我想要用户滚动滚轮可以卷动这个Form。请问怎么做?...
我的C# Win Form里面有一个richtextbox, 当焦点在这个richtextbox的时候,我想要用户滚动滚轮可以卷动这个Form。请问怎么做?
展开
2个回答
展开全部
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.richTextBox1.MouseWheel += new 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);
{
public Form1()
{
InitializeComponent();
this.richTextBox1.MouseWheel += new 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);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.richTextBox1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.richTextBox1_MouseWheel);
}
private void richTextBox1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
int numberOfPixelsToMove = numberOfTextLinesToMove * fontSize;
if (numberOfPixelsToMove != 0) {
System.Drawing.Drawing2D.Matrix translateMatrix = new System.Drawing.Drawing2D.Matrix();
translateMatrix.Translate(0, numberOfPixelsToMove);
mousePath.Transform(translateMatrix);
}
richTextBox1.Invalidate();
}
}
{
public Form1()
{
InitializeComponent();
this.richTextBox1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.richTextBox1_MouseWheel);
}
private void richTextBox1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
int numberOfPixelsToMove = numberOfTextLinesToMove * fontSize;
if (numberOfPixelsToMove != 0) {
System.Drawing.Drawing2D.Matrix translateMatrix = new System.Drawing.Drawing2D.Matrix();
translateMatrix.Translate(0, numberOfPixelsToMove);
mousePath.Transform(translateMatrix);
}
richTextBox1.Invalidate();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询