捕获自定义 SplitContainerDesigner 的鼠标事件

发布于 2024-09-09 15:49:10 字数 748 浏览 0 评论 0原文

我正在尝试创建一个用户控件,该控件将在自定义 IDesignerHost 实现中提供两个面板之间的可拖动拆分器(与 SplitContainer 完全相同)。据我所知,SplitContainer 本身不是一个选择;除非在 Visual Studio 的设计器中使用,否则它将引发异常。

我的实现大致类似于这个,只是我没有收到必要的鼠标事件。我已经尝试过事件处理程序、On* 覆盖和覆盖用户控件本身、主机控件和父窗体中的 WndProc,但我似乎没有收到WM_MOUSEMOVEWM_LBUTTONDOWNWM_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

oО清风挽发oО 2024-09-16 15:49:10

事实证明这很容易——只要你知道怎么做。

  1. 将控件上的 Designer 属性设置为继承自 ControlDesigner 的自定义类。
  2. 重写 OnSetCursor 方法,以便在分割器区域上方时分别显示 HSplitVSplit 光标。 根据此票,确保设置控件的光标(这将导致堆栈溢出、崩溃或其他不稳定的行为,当然不是您想要的),而是设置Cursor.Current代码>.
  3. 覆盖 OnMouseDragBeginOnMouseDragMoveOnMouseDragEnd 以调整内部面板的大小。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文