简体   繁体   中英

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 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.

  1. Set the Designer attribute on the control to a custom class that inherits from ControlDesigner .
  2. Override the OnSetCursor method so that, while over the splitter region, you show the HSplit or VSplit 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 rather Cursor.Current .
  3. Override OnMouseDragBegin , OnMouseDragMove and OnMouseDragEnd to resize the inner panels.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM