'先设置窗体 KeyPreview 属性为 True 【只能手动设置】
'按下 红X关闭
'按下 Esc关闭
'按下 鼠标中键 确定
'记录窗体位置
Dim ini As String
Dim nx As Integer
Dim ny As Integer
'判断窗口是按下按下红X关闭
Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)
If unloadmode <> 1 Then
'遇到错误,直接执行下一行。
On Error Resume Next
nx = Form1.Left
ny = Form1.Top
lngHandle = FreeFile() '取得句柄
Open ini For Output As lngHandle
Print #lngHandle, RTrim$(LTrim$(Str(nx))) & vbCrLf & RTrim$(LTrim$(Str(ny)))
Close lngHandle
End
End If
End Sub
'先把Form窗体的KeyPreview设置为True
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
'遇到错误,直接执行下一行。
On Error Resume Next
nx = Form1.Left
ny = Form1.Top
lngHandle = FreeFile() '取得句柄
Open ini For Output As lngHandle
Print #lngHandle, RTrim$(LTrim$(Str(nx))) & vbCrLf & RTrim$(LTrim$(Str(ny)))
Close lngHandle
End
End If
End Sub
Private Sub Form_Load()
'遇到错误,直接执行下一行。
On Error Resume Next
ini = "D:\Mr.Mei\Parameters\INI\BOM_OBJ.mei" '记录窗体位置参数保存文件
nx = (Screen.Width - Form1.Width) / 2
ny = (Screen.Height - Form1.Height) / 2
If Dir(ini) <> "" Then
i = 0
Open ini For Input As #1
Do While Not EOF(1)
Line Input #1, temp
i = i + 1
If i = 1 Then nx = Abs(Int(Val(temp)))
If i = 2 Then ny = Abs(Int(Val(temp)))
Loop
Close #1
End If
Form1.Left = nx
Form1.Top = ny
End Sub
'判断鼠标中建按下
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbKeyMButton Then Call 确定
End Sub
Sub 确定()
'遇到错误,直接执行下一行。
On Error Resume Next
nx = Form1.Left
ny = Form1.Top
lngHandle = FreeFile() '取得句柄
Open ini For Output As lngHandle
Print #lngHandle, RTrim$(LTrim$(Str(nx))) & vbCrLf & RTrim$(LTrim$(Str(ny)))
Close lngHandle
End
End Sub
|