问题
I have made a MDI (tabbed) application that uses PictureBoxes inside TabPages. The picturebox is sometimes larger then the tabpage, so scrollbars appear. It is written in C# using Windows Forms.
Inside my tabpage, I capture and process mouse wheel events in the MouseWheel event (i use it to rotate some objects I draw in the picturebox).
But when I have the scrollbars, when I rotate the mouse wheel, my objects rotate, but the tabpage also scrolls down.
How can I make the tabpage not process the mousewheel event, and thus make it not scroll down? I want it to only be scrollable if the user clicks and drags on the scrollbar.
回答1:
Subclass TabPage
and override the WndProc()
method to ignore the WM_MOUSEWHEEL
message:
public class MyTabPage : TabPage
{
private const int WM_MOUSEWHEEL = 0x20a;
protected override void WndProc(ref Message m)
{
// ignore WM_MOUSEWHEEL events
if (m.Msg == WM_MOUSEWHEEL)
{
return;
}
base.WndProc(ref m);
}
}
Then use your MyTabPage
subclass in place of the standard TabPage
.
来源:https://stackoverflow.com/questions/1351046/make-tabpage-not-process-mousewheel-events-c