只要能做到在一个主窗体form1上有一个隐藏在屏幕左边(或上边)的另一窗体form2(有30个按钮设置在此窗体上),只要鼠标靠近屏幕左边缘,form2就弹出来,就可以在此窗体上操作30个按钮之一.当鼠标移开form2,该窗体收回屏幕左边隐藏起来.下面有一段代码,但有错,请看一下如何解决?
有下面一段代码,但运行后还有些问题,请你验证一下,看问题出在何处?
1.模块的代码
------------
Option Explicit
Declare Function GetSystemMenu Lib "user32" (ByVal hwnd _
As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As _
Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Dim JsForm2 As Boolean 'Form2启动标记
Dim JSQ As Integer
2.Form2的代码
-------------
Sub Form_Load()
On Error Resume Next
Dim hMenu As Long
hMenu = GetSystemMenu(hwnd, False)
RemoveMenu hMenu, 4, &H400& '关闭窗体最大化按纽(偶不需要这个功能)
RemoveMenu hMenu, 3, &H400& '关闭窗体最小化按纽(偶不需要这个功能)
End Sub
Private Sub Form_Click() '单击窗体隐藏(偶不需要这个功能,要求鼠标离开,窗体就隐藏)
If Me.Top > 0 Then JSQ = 2: Form1.Timer1.Interval = 10: Form1.Timer1.Enabled = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If JsForm2 And Me.Top < 0 Then JSQ = 2: Form1.Timer1.Interval = 10: Form1.Timer1.Enabled = True
End Sub
3.Form1的代码
-------------
Option Explicit
Private Sub Command1_Click()'(偶不要加按钮,而是鼠标靠近屏幕边上,隐藏窗口就弹出)
JSQ = 2: Form2.Show
End Sub
private Sub Timer1_Timer()
If JSQ = 0 Then Timer1.Enabled = False: Exit Sub
If JsForm2 Then
If Form2.Top > 540 Then JsForm2 = False: JSQ = 0 Else Form2.Top = Form2.Top + 60
Else
If Form2.Top < 160 - Form2.Height Then JsForm2 = True: JSQ = 0 Else Form2.Top = Form2.Top - 60
End If
End Sub