Private Sub Form1_MouseUp(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
Dim x, y
x = e.X
y = e.Y'获得新的x,y的坐标
If Button1.Enabled = False Then
Button1.Top = y
Button1.Left = x'坐标替换
End If
If TextBox1.Enabled = False Then
TextBox1.Top = y
TextBox1.Left = x
End If
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MenuItem2.Click
Button1.Enabled = False'禁止控件响应事件
If TextBox1.Enabled = False Then
TextBox1.Enabled = True
End If
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MenuItem3.Click
TextBox1.Enabled = False
If Button1.Enabled = False Then
Button1.Enabled = True
End If
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MenuItem4.Click
TextBox1.Enabled = True
Button1.Enabled = True
'将新的坐标保存到文本文件中
If IO.File.Exists("c:\k.txt") = True Then
IO.File.Delete("c:\txt")
Dim sw As IO.StreamWriter = IO.File.CreateText("c:\k.txt")
Dim cstringt, cstringl As String
Dim tstringt, tstringl As String
cstringt = Button1.Top
cstringl = Button1.Left
tstringt = TextBox1.Top
tstringl = TextBox1.Left
sw.WriteLine(cstringt)'写入新坐标到文本文件中
sw.WriteLine(cstringl)
sw.WriteLine(tstringt)
sw.WriteLine(tstringl)
sw.Close()
Else
Dim sw As IO.StreamWriter = IO.File.CreateText("c:\k.txt")
Dim cstringt, cstringl As String
Dim tstringt, tstringl As String
cstringt = Button1.Top
cstringl = Button1.Left
tstringt = TextBox1.Top
tstringl = TextBox1.Left
sw.WriteLine(cstringt)
sw.WriteLine(cstringl)
sw.WriteLine(tstringt)
sw.WriteLine(tstringl)
sw.Close()
End If
MsgBox("当前界面已经保存")
End Sub
Private Sub Form1_Load(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists("c:\k.txt") = True Then
Dim sr As IO.StreamReader = IO.File.OpenText("c:\k.txt")
Dim input1, input2, input3, input4 As String
input1 = sr.ReadLine
input2 = sr.ReadLine
input3 = sr.ReadLine
input4 = sr.ReadLine'读取文件中的坐标
Button1.Top = input1
Button1.Left = input2
TextBox1.Top = input3
TextBox1.Left = input4'用文件中的值来初始化控件在界面中的位置
sr.Close()
End If
End Sub
|