Catching mouse events for a custom SplitContainerDesigner
I'm trying to create a user control that will provide a draggable splitter between two panels — exactly like SplitContainer — in a custom IDesignerHost implementation. SplitContainer开发者_如何学C itself, as far as I can tell, is not an option; it will raise an exception unless used in Visual Studio's Designer.
My implementation would look roughly like this, except that I'm not receiving the necessary mouse events. I've tried event handlers, On*
overrides and overriding WndProc
in the user control itself, the host control, and the parent form, but I don't appear to receive WM_MOUSEMOVE
, WM_LBUTTONDOWN
or WM_LBUTTONUP
events anywhere. Per this bug report, I should be receiving WM_MOUSEMOVE
in "the control designer"; I'm not sure what that refers to in this case.
Any ideas how I can implement a draggable splitter?
Turns out this is easy — once you know how.
- Set the
Designer
attribute on the control to a custom class that inherits fromControlDesigner
. - Override the
OnSetCursor
method so that, while over the splitter region, you show theHSplit
orVSplit
cursor, respectively. Per this ticket, make sure not to set the control's cursor (this will cause a stack overflow, crash, or other erratic behavior, and certainly not what you want), but ratherCursor.Current
. - Override
OnMouseDragBegin
,OnMouseDragMove
andOnMouseDragEnd
to resize the inner panels.
精彩评论