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 scrol
Yes, you will have to capture the .MouseWheel and .MouseMove events. See this post.
Ok, do something like following:
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();
}
}
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: