Re: How to raise event trapping mouse wheel scroll?
Looks like only way is to perform a hook. I dont want to use WH_MOUSE_LL, so how about instead overriding wndProc in my user control to trap WM_MOUSEWHEEL, then just raise a custom event with the delta value? Is this possible. Is this how I should do it?
Re: How to raise event trapping mouse wheel scroll?
Ok here's my override of wndProc. If I left click on my user control white space(where I dont have any child controls) I get my messagebox for left mouse click. If I scroll the wheel in same area, It doesnt see it. I assume its because when you click the user control has focus for a moment. Ok, I'll live with not being able to scroll when mouse is over the user control white space. So I commented out this statement if (msg.HWnd != this.Handle) so that all messages will be received. But the problem persists. Even if I click on the child object to bring focus like a text box, it still doesnt see the WM_MOUSEWHEEL, or WM_LBUTTONDOWN
Code:
protected override void WndProc(ref Message msg)
{
base.WndProc(ref msg);
if (msg.HWnd != this.Handle)
return;
switch (msg.Msg)
{
case WM_LBUTTONDOWN:
MessageBox.Show("Left Button Down");
break;
case WM_MOUSEWHEEL:
MessageBox.Show("Scroll!!!!!");
try
{
int zDelta = HiWord((int)msg.WParam);
int y = HiWord((int)msg.LParam);
int x = LoWord((int)msg.LParam);
System.Windows.Forms.MouseButtons butt;
switch (LoWord((int)msg.WParam))
{
case MK_LBUTTON:
butt = System.Windows.Forms.MouseButtons.Left;
break;
case MK_MBUTTON:
butt = System.Windows.Forms.MouseButtons.Middle;
break;
case MK_RBUTTON:
butt = System.Windows.Forms.MouseButtons.Right;
break;
case MK_XBUTTON1:
butt = System.Windows.Forms.MouseButtons.XButton1;
break;
case MK_XBUTTON2:
butt = System.Windows.Forms.MouseButtons.XButton2;
break;
default:
butt = System.Windows.Forms.MouseButtons.None;
break;
}
System.Windows.Forms.MouseEventArgs arg0 = new System.Windows.Forms.MouseEventArgs(butt, 1, x, y, zDelta);
this.ScrollMouseWheel(this, arg0);
}
catch (Exception) { }
break;
default:
break;
}
}
Re: How to raise event trapping mouse wheel scroll?
Ok, i'm getting close(I ditched the wndProc idea). In order to use the mousewheel to scroll the panel of user controls, the panel needs to have focus. So now I need to raise events from my user control that tell me when the mouse has entered visability of the labels. Then in my main form, I can trap those events, and set focus to the panel. Sounds pretty easy. Well for me and my NOOBNESS, its not. I am getting an error when trying to pass the mouse enter event for a label control. Here is my code.
Code:
publicevent System.EventHandler NoFocus;
privatevoid label2_MouseEnter(object sender, EventArgs e)
{
NoFocus(sender,e); // Object reference not set to an instance of an object.
}
and I get this error
Quote:
Object reference not set to an instance of an object.
the arg sender shows the label control that generated the event, and e is empty. NoFocus = null. I think this is the problem. How do I fix it?
Please help....... This has got to be an easy one for you guys.
Re: How to raise event trapping mouse wheel scroll?
I tried adding this statement
newDetails.NoFocus += newEventArgs(NoFocus);
when I create an instance of my user control(named newDetails) and I get a compile error.
Quote:
Error 3 No overload for method 'EventArgs' takes '1' arguments
I have defined NoFocus as this.....
Code:
privatevoid NoFocus(object sender, EventArgs e)
{
splitContainer2.Panel2.Focus();
}
Re: How to raise event trapping mouse wheel scroll?
I'm stupid. I knew it was something easy.
newDetails.NoFocus += newEventArgs(NoFocus);
Needed to be........
newDetails.NoFocus += newEventHandler(NoFocus);
Works great now. Got my panel scrolling the user controls.