Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.NET使用鼠标移动对象_Vb.net_Object_Customization - Fatal编程技术网

VB.NET使用鼠标移动对象

VB.NET使用鼠标移动对象,vb.net,object,customization,Vb.net,Object,Customization,我在考虑创建一个表单,用户可以在其中移动不同的对象,如文本框、标签和图片框。我在互联网上搜索相似的东西,但找不到正确的东西。我编写的代码现在可以正常工作,但只要我在调试之前手动分配对象即可。你知道我怎么才能拿到这个东西吗 这是我到现在为止得到的代码: Public Class Form1 Dim cursorposx As Integer Dim cursorposy As Integer Dim currentobj As Object Private Sub Form1_MouseMove

我在考虑创建一个表单,用户可以在其中移动不同的对象,如文本框、标签和图片框。我在互联网上搜索相似的东西,但找不到正确的东西。我编写的代码现在可以正常工作,但只要我在调试之前手动分配对象即可。你知道我怎么才能拿到这个东西吗

这是我到现在为止得到的代码:

Public Class Form1
Dim cursorposx As Integer
Dim cursorposy As Integer
Dim currentobj As Object

Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
    cursorposx = e.X
    cursorposy = e.Y
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    If Not currentobj = Nothing Then

        Label1.Text = cursorposx

        Label2.Text = cursorposy

        currentobj.Location = New Point(cursorposx, cursorposy)
    End If
End Sub
我搜索一种方法,在单击对象时将变量“currentObj”指定给对象

多谢各位

编辑:

我会按照拉尔斯泰克对我的看法来尝试。
+我将使用对象列表,以便为它们编制索引。

您可以从每个控件的MouseDown事件中的sender参数中获取对象。但是有没有一种方法可以使用它而不必为每个对象定义它?因为我不想让用户创建子对象,这是最简单的方法。您可以为每个控件分配相同的事件处理程序。好的,非常感谢。我更新了我的帖子