UserControl事件问题

编程入门 行业动态 更新时间:2024-10-08 22:55:38
本文介绍了UserControl事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我编写了一个控件,以在运行时将用户控件运行正常.但是,当我添加标签控件并将其停靠以填充它时,它在运行时就停止了移动. 谁能告诉我解决方案这怎么可能 代码如下:

I have written a control to move a usercontrol at run time it was working fine. But when i added a label control and docked it to fill this has stopped moving at runtime. Can anybody tell me the solution how this is possible code is as bellow :

Private Sub CtrlMover1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CtrlMover1.MouseDown If e.Button = Windows.Forms.MouseButtons.Left Then CtrlMover1.Capture = False Dim msg As Message = Message.Create(CtrlMover1.Handle, WM_NCLBUTTONDOWN, New IntPtr(HTCAPTION), IntPtr.Zero) Me.DefWndProc(msg) End If End Sub

但是当我在将用户控件闪烁放置在窗体上的窗体上处理MouseDown,MouseMove和MouseUp时,图片

But when i handles MouseDown, MouseMove, and MouseUp the Picture on the form where i put user control flickers

推荐答案

这与停靠无关.顺便说一句,为什么您曾经将Label停靠到DockStyle.Fill?我会理解的是它是DockStyle.Top. 现在,好像您的动作混乱了: 1)您需要处理MouseDown,MouseUp和MouseMove. 2)为此,您无需创建任何消息并将P/Invoke用于任何Windows API.相反,您只需要更改要移动的对象的位置即可. 3)您可能会也可能不会使用鼠标捕获.如果这样做,则需要使用相同的按钮在MouseDown的处理程序中开始鼠标捕获(而不是停止捕获),在MouseMove的处理程序中进行实际移动,并在MouseUp的处理程序中停止捕获,大概留下了一个.
—SA
This is not related to dock. By the way, why do you dock the Label to DockStyle.Fill, ever? I would understand is it is DockStyle.Top. Now, it looks like you motion is messed up: 1) You need need to handle MouseDown, MouseUp and MouseMove. 2) You never need to create any message and use P/Invoke for any Windows API for this purpose. Instead, you just need to change Location of the object you''re moving. 3) You may or may not use mouse capture. If you do it, you need to start mouse capture in the handler of MouseDown (not stop capturing), do actual move in the handler of MouseMove and stop capture in the handler of MouseUp, with the same button, presumably left one.
—SA

您要移动的UserControl是一个具有其自身表面的容器.您可能正在处理UserControl事件,以使用鼠标进行运行时移动.现在已经有一个标签覆盖了整个UserControl空间,鼠标事件不再是进入UserControl,而是进入该标签. 要么更改标签,以便您可以看到UserControl界面,要么重写事件处理程序以改为使用标签鼠标事件. The UserControl you''re moving is a container with its own surface. You''re probably handling the UserControl events to do the runtime-move with the mouse. Now that there is a label that is covering the entire UserControl space, the mouse events are no longer going to the UserControl, but to the label. Either change the label so you can see the UserControl surface or rewrite the eventhandlers to use the label mouse events instead.

更多推荐

UserControl事件问题

本文发布于:2023-11-11 08:42:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577920.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   UserControl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!