UserControl事件问题 [英] UserControl Events Question

查看:85
本文介绍了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)您需要处理MouseDownMouseUpMouseMove.

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事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆