隐藏一个RichTextBox的滚动条 [英] Hide scrollbars of a RichTextBox
问题描述
我试图写这样的暗房一个简单的文本编辑器,只是一个RichTextBox(或者一个TextBox)在里面。我的问题是,我不能使用鼠标滚轮的滚动,除非我有一个垂直滚动条。有什么办法来隐藏这个滚动条,仍然能够滚动鼠标滚轮?
I'm trying to write a simple text editor like DarkRoom with just a RichTextBox (or alternatively a TextBox) in it. My problem is that I can't use the mouse wheel for scrolling unless I have a vertical scrollbar. Is there any way to hide this scrollbar and still be able to scroll with the mouse wheel?
到目前为止,我有几个想法怎么可以这样做,但不知道如何实现它们。
So far I have several ideas how this could be done, but no idea how to implement them.
- 使用鼠标滚轮事件 重新创建滚动code
- 改变滚动条的视觉风格,以隐藏它或使其不太明显
- 在写我自己的TextBox控件
- 在重叠用别的东西来隐藏他们的滚动条
- re-create the scrolling code using a MouseWheel event
- change the visual style of the scrollbar to hide it or make it less visible
- write my own TextBox widget
- overlap the scrollbars with something else to hide them
PS:使用任意的Win32的东西是不是一种选择
P.S.: Using any win32 stuff is not an option.
推荐答案
是的,你必须捕捉.MouseWheel和.MouseMove事件。请参阅<一href="http://social.msdn.microsoft.com/forums/en-US/winforms/thread/8e83865a-0cb9-4e7a-94db-356d542e5680/"相对=nofollow>这个帖子。
Yes, you will have to capture the .MouseWheel and .MouseMove events. See this post.
好了,像做以下操作:
-
添加一行形式加载事件。
Add a line in form load event.
private void Form1_Load(object sender, EventArgs e)
{
this.richTextBox1.MouseWheel += new MouseEventHandler(richTextBox1_MouseWheel);
}
添加鼠标滚轮事件以下。
Add following in mouse wheel event.
void richTextBox1_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta > 0)
{
//Handle mouse move upwards
if (richTextBox1.SelectionStart > 10)
{
richTextBox1.SelectionStart -= 10;
richTextBox1.ScrollToCaret();
}
}
else
{
//Mouse move downwards.
richTextBox1.SelectionStart += 10;
richTextBox1.ScrollToCaret();
}
}
让我知道,在这两种情况下,如果你想的一样运行样本;或者,如果你不喜欢的解决方案(0:
Let me know in either cases, if you would want the running sample of the same; or if you are not liking the solution (0:
这篇关于隐藏一个RichTextBox的滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!