I want to hook a mouse wheel event to my scroll bar but i cannot see mouse wheel event in control properties. I have a form on which i have a panel and a vertical scroll bar. So far my scroll bar doesn't work with the mouse wheel. I need that event to hook it with my scroll bar. How to do it??
views:
41answers:
1
+4
A:
You need to attach to the MouseWheel event:
Occurs when the mouse wheel moves while the control has focus.
For example:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.MouseWheel += new MouseEventHandler(MouseWheelEvent);
this.MouseMove += new MouseEventHandler(MouseWheelEvent);
}
private void MouseWheelEvent(object sender, MouseEventArgs e)
{
Console.Out.WriteLine(e.Delta);
}
}
SwDevMan81
2010-07-20 11:28:16
but how to make it work that is make it scroll when i roll the mouse wheel? It is not working!
ghd
2010-07-20 11:51:36
I have a custom scroll bar and not auto scroll bar.
ghd
2010-07-20 11:57:09
Check out http://stackoverflow.com/questions/262534/how-to-scroll-a-panel-manually. Then you could put something like c.VerticalScroll.Value += e.Delta; in the MouseWheelEvent above. Is that more what you are looking for?
SwDevMan81
2010-07-20 12:15:15