怎么利用top和left属性 来实现“我喜欢学vb”的移动 在横坐标和纵坐标...
发布网友
发布时间:2024-08-18 21:47
我来回答
共2个回答
热心网友
时间:2024-08-22 12:29
Private Sub Command1_Click()
Label1.Top = Label1.Top - Val(Text3.Text)
Text2.Text = Label1.Top
End Sub
Private Sub Command2_Click()
Label1.Top = Label1.Top + Val(Text3.Text)
Text2.Text = Label1.Top
End Sub
Private Sub Command3_Click()
Label1.Left = Label1.Left - Val(Text3.Text)
Text1.Text = Label1.Left
End Sub
Private Sub Command4_Click()
Label1.Left = Label1.Left + Val(Text3.Text)
Text1.Text = Label1.Left
End Sub
Private Sub Command5_Click()
Label1.Top = Val(Text2.Text)
Label1.Left = Val(Text1.Text)
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
Text1.Text = Label1.Left
Text2.Text = Label1.Top
Text3.TabIndex = 0
End Sub
设计界面:
热心网友
时间:2024-08-22 12:28
假定那三个文本框分别是Text1、Text2、Text3,“确定坐标”按钮为Command1,红色字的标签为Label1,下面的四个按钮假定分别是Command2、Command3、Command4、Command5(本来这些都是需要你提供的,现在只好猜了,如果不对自己修改)。代码如下:
Private Sub Command1_Click() '确定坐标
Label1.Move Val(Text1.Text), Val(Text2.Text)
End Sub
Private Sub Command2_Click() '向上
Label1.Top = Label1.Top - Val(Text3.Text)
End Sub
Private Sub Command3_Click() '向下
Label1.Top = Label1.Top + Val(Text3.Text)
End Sub
Private Sub Command4_Click() '向左
Label1.Left = Label1.Left - Val(Text3.Text)
End Sub
Private Sub Command5_Click() '向右
Label1.Left = Label1.Left + Val(Text3.Text)
End Sub