捕获自定义 SplitContainerDesigner 的鼠标事件
我正在尝试创建一个用户控件,该控件将在自定义 IDesignerHost 实现中提供两个面板之间的可拖动拆分器(与 SplitContainer 完全相同)。据我所知,SplitContainer 本身不是一个选择;除非在 Visual Studio 的设计器中使用,否则它将引发异常。
我的实现大致类似于这个,只是我没有收到必要的鼠标事件。我已经尝试过事件处理程序、On*
覆盖和覆盖用户控件本身、主机控件和父窗体中的 WndProc
,但我似乎没有收到WM_MOUSEMOVE
、WM_LBUTTONDOWN
或 WM_LBUTTONUP
事件任何地方。根据 这个错误报告,我应该在“控件设计器”中收到WM_MOUSEMOVE
;我不确定在这种情况下它指的是什么。
有什么想法可以实现可拖动的拆分器吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明这很容易——只要你知道怎么做。
Designer
属性设置为继承自ControlDesigner
的自定义类。OnSetCursor
方法,以便在分割器区域上方时分别显示HSplit
或VSplit
光标。 根据此票,确保不设置控件的光标(这将导致堆栈溢出、崩溃或其他不稳定的行为,当然不是您想要的),而是设置Cursor.Current代码>.
OnMouseDragBegin
、OnMouseDragMove
和OnMouseDragEnd
以调整内部面板的大小。Turns out this is easy — once you know how.
Designer
attribute on the control to a custom class that inherits fromControlDesigner
.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
.OnMouseDragBegin
,OnMouseDragMove
andOnMouseDragEnd
to resize the inner panels.