如何在其面板内移动标签移动 [英] How to make movable label move within its panel only

查看:84
本文介绍了如何在其面板内移动标签移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Sir / Mam我很难在网上搜索关于在其面板中移动标签的问题。我已经知道如何移动在运行时创建的标签,但标签在面板中不断移出。我自己尝试了这个代码:

 如果(label.Left + label.Width)= panel .Width 然后 

结束 如果

如果(label.Top + label.Height)= panel.Height 然后

结束 如果





但是我被卡住了,但仍然不知道该怎么做。我希望你能给出一些建议或想法。先谢谢先生/妈妈。

解决方案

Hello Kim,

这会在面板容器内移动一个标签。它不会检查或限制旅行,但你应该能够弄明白。坐标的关键是使用Control.PointToClient方法。



 公共  Sub  ()
' 此表单有一个Panel容器Panel1和一个Label Label1
' 设计者需要此调用。
InitializeComponent()
结束 Sub
Dim _isMoving As Boolean
Dim _pt As Point
私有 Sub Label1_MouseDown(发件人 As 对象 ,e As MouseEventArgs)句柄 Label1.MouseDown
_isMoving = True
_pt = 点(eX,eY)
结束 Sub
私有 Sub Label1_MouseUp(发件人作为 对象,e 作为 MouseEventArgs)句柄 Label1.MouseUp
_isMoving = False
结束 Sub
私有 Sub Label1_MouseMove(发件人作为 对象,e As MouseEv entArgs)句柄 Label1.MouseMove
Dim pos As Point = Panel1.PointToClient(Cursor.Position)
pos.X = pos.X - _pt.X
pos.Y = pos.Y - _pt.Y
< span class =code-keyword>如果 _isMoving 那么
Label1.Location = pos
结束 如果
结束 Sub





希望有所帮助,



regs



ron O。


您必须将Label控件设置为父容器,该容器将作为面板。通过这样做,它不会从指定的父母移出。



试试这段代码,而不是用我的电脑,用手机写字。



Label1.ParentContainer(Panel1)



在需要的地方试一试并进行更正!

Hello Sir/Mam I am having hard time searching over and over the net about moving a label within its panel. I already know how to move a label created in run time but the label keeps moving out in a panel. I tried this code on my own:

If (label.Left + label.Width) = panel.Width Then
            
End If

If (label.Top + label.Height) = panel.Height Then
                
End If



But i am stuck and still don't know what to do. I hope you can give some advice's or ideas. Thanks in advance sir/mam.

解决方案

Hello Kim,
This will move a label inside the panel container. It does not check or limit the travel but you should be able to figure that out. The key to the coordinate is using the Control.PointToClient method.

Public Sub New()
    'This form has a Panel container Panel1 and a Label Label1
    ' This call is required by the designer.
    InitializeComponent()
End Sub
Dim _isMoving As Boolean
Dim _pt As Point
Private Sub Label1_MouseDown(sender As Object, e As MouseEventArgs) Handles Label1.MouseDown
    _isMoving = True
    _pt = New Point(e.X, e.Y)
End Sub
Private Sub Label1_MouseUp(sender As Object, e As MouseEventArgs) Handles Label1.MouseUp
    _isMoving = False
End Sub
Private Sub Label1_MouseMove(sender As Object, e As MouseEventArgs) Handles Label1.MouseMove
    Dim pos As Point = Panel1.PointToClient(Cursor.Position)
    pos.X = pos.X - _pt.X
    pos.Y = pos.Y - _pt.Y
    If _isMoving Then
        Label1.Location = pos
    End If
End Sub



Hope that helps,

regs

ron O.


You have to set the Label control to a parent container of which will be the panel. By so doing, it won't move out from the assigned parent.

Try out this code, not actually with my PC, writing from a mobile phone.

Label1.ParentContainer(Panel1)

Give it a go and make some corrections where needed!


这篇关于如何在其面板内移动标签移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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