有下面一段代码,但运行后还有些问题,请哪位高手指教一下: 1.模块的代码 ------------ Option ExplicitDeclare 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 LongDim JsForm2 As Boolean 'Form2启动标记 Dim JSQ As Integer2.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 SubPrivate Sub Form_Click() '单击窗体隐藏(偶不需要这个功能,要求鼠标离开,窗体就隐藏)If Me.Top > 0 Then JSQ = 2: Form1.Timer1.Interval = 10: Form1.Timer1.Enabled = True End SubPrivate 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 ExplicitPrivate Sub Command1_Click()'(偶不要加按钮,而是鼠标靠近屏幕边上,隐藏窗口就弹出) JSQ = 2: Form2.Show End Subrivate 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 在上面代码制作完成后,出现问题如下: 运行后,出现:编译错误,变量未定义: Private Sub Command1_Click()<这一行出现黄底> JSQ = 2: Form2.Show<这一行JSQ =出现兰底> End Sub rivate Sub Timer1_Timer()<这一行是红字> 请问应如何解决上面问题?如何实现偶提出的功能?
上面的构思是将30个按钮绑定后放进form2窗体,并由此窗体实现隐藏功能.
JSQ 没有在form2中定义,由于是公共变量 你在模块中定义的时候不能用dim要用public即把模块中最后1行的Dim JSQ As Integer改为public JSQ As Integer rivate Sub Timer1_Timer()当然是红的private Sub Timer1_Timer()才对
谢谢Alzzl(果子林)的更正,修改后出现下面错误:"子程序或函数未定义" Private Sub Form_Load()(这一行黄底) On Error Resume Next Dim hMenu As Long hMenu = GetSystemMenu(hwnd, False) RemoveMenu hMenu, 4, &H400&, 关闭窗体最大化按纽(RemoveMenu兰底) RemoveMenu hMenu, 3, &H400&, 关闭窗体最小化按纽 End Sub Private Sub Form_Click() '单击窗体隐藏(还是红字) 问题出在何处?
Option Explicit Private Type PointAPI x As Long y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long Private mPos As PointAPIPrivate Sub Timer1_Timer() GetCursorPos mPos If mPos.x < 10 Then Form2.Show End Sub没有用你的思路 你把timer1的interval调小点我用的60
忘了隐藏的部分了,改一下 Private Sub Timer1_Timer() GetCursorPos mPos If mPos.x < 10 Then Form2.Show else form2.visible=false endif End Sub
请问果子林,修改以后完成的全部代码是下面这样的吗? 按下面的代码运行后,屏幕上只有窗体form1,而未出现窗体form2,请看一下问题何在?谢谢! 1.模块的代码修改后 ------------ Option ExplicitDeclare 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 LongDim JsForm2 As Boolean 'Form2启动标记 public JSQ As Integer2.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 SubPrivate Sub Form_Click() '单击窗体隐藏If Me.Top > 0 Then JSQ = 2: Form1.Timer1.Interval = 10: Form1.Timer1.Enabled = True End SubPrivate 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 Sub3.Form1的代码修改后 -------------Option Explicit Private Type PointAPI x As Long y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long Private mPos As PointAPIPrivate Sub Timer1_Timer() GetCursorPos mPos If mPos.x < 10 Then Form2.Show else form2.visible=false endif End Sub
模块: Option ExplicitPublic Type PointAPI X As Long Y As Long End Type Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long Public mPos As PointAPIPublic Declare Function GetSystemMenu Lib "user32" (ByVal hwnd _ As Long, ByVal bRevert As Long) As Long Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As _ Long, ByVal nPosition As Long, ByVal wFlags As Long) As LongPublic JsForm2 As Boolean ' Form2启动标记 Public JSQ As Integerform1:Option ExplicitPrivate Sub Form_Load() Timer1.Interval = 60 End SubPrivate Sub Timer1_Timer() GetCursorPos mPos If mPos.X < 10 Then Form2.Show Else Form2.Visible = False End If End Subform2: 不用代码
你好,果子林,按照新程序运行还有点问题,编译错误,变量未定义: Private Sub Form_Load()(这一行黄底) Timer1.Interval = 60(这一行前面Timer1兰底) End Sub 请问如何更正.
首先把你的窗体设为topmost,保证在被其他topmost窗体遮盖时,能正常置顶
方法1:隐藏后,判断mouse_move事件,如果是隐藏状态,就显示完整的窗体
方法2:隐藏后用GetCursorPos这个api判断鼠标指针当前的位置,如果是在屏幕左边就显示你的窗体
推荐方法2,应为topmost窗体会被同为topmost的窗体所遮盖,如果你的窗体被一个topmost的窗体遮盖了
那么方法1就会失效,而方法2是不用触发窗体的事件而实现的
1.模块的代码
------------ Option ExplicitDeclare 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 LongDim JsForm2 As Boolean 'Form2启动标记
Dim JSQ As Integer2.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 SubPrivate Sub Form_Click() '单击窗体隐藏(偶不需要这个功能,要求鼠标离开,窗体就隐藏)If Me.Top > 0 Then JSQ = 2: Form1.Timer1.Interval = 10: Form1.Timer1.Enabled = True
End SubPrivate 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 ExplicitPrivate Sub Command1_Click()'(偶不要加按钮,而是鼠标靠近屏幕边上,隐藏窗口就弹出)
JSQ = 2: Form2.Show
End Subrivate 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
在上面代码制作完成后,出现问题如下:
运行后,出现:编译错误,变量未定义:
Private Sub Command1_Click()<这一行出现黄底>
JSQ = 2: Form2.Show<这一行JSQ =出现兰底>
End Sub
rivate Sub Timer1_Timer()<这一行是红字>
请问应如何解决上面问题?如何实现偶提出的功能?
rivate Sub Timer1_Timer()当然是红的private Sub Timer1_Timer()才对
Private Sub Form_Load()(这一行黄底)
On Error Resume Next
Dim hMenu As Long
hMenu = GetSystemMenu(hwnd, False)
RemoveMenu hMenu, 4, &H400&, 关闭窗体最大化按纽(RemoveMenu兰底)
RemoveMenu hMenu, 3, &H400&, 关闭窗体最小化按纽
End Sub
Private Sub Form_Click() '单击窗体隐藏(还是红字)
问题出在何处?
至于Form_Click为什么红字我也不太清楚,你贴上来的代码用的是'(全角)作注释符,如果代码里也是的话,将其改成半角的'再试试
可否提供一个完整的代码,就是有两个窗体;一个窗体form1,一个隐藏在屏幕左边(或上边)的窗体form2.当鼠标靠近屏幕边,自动弹出窗体form2.鼠标一离开就隐藏.
Private Type PointAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Private mPos As PointAPIPrivate Sub Timer1_Timer()
GetCursorPos mPos
If mPos.x < 10 Then Form2.Show
End Sub没有用你的思路
你把timer1的interval调小点我用的60
Private Sub Timer1_Timer()
GetCursorPos mPos
If mPos.x < 10 Then
Form2.Show
else
form2.visible=false
endif
End Sub
按下面的代码运行后,屏幕上只有窗体form1,而未出现窗体form2,请看一下问题何在?谢谢!
1.模块的代码修改后
------------ Option ExplicitDeclare 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 LongDim JsForm2 As Boolean 'Form2启动标记
public JSQ As Integer2.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 SubPrivate Sub Form_Click() '单击窗体隐藏If Me.Top > 0 Then JSQ = 2: Form1.Timer1.Interval = 10: Form1.Timer1.Enabled = True
End SubPrivate 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 Sub3.Form1的代码修改后
-------------Option Explicit
Private Type PointAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Private mPos As PointAPIPrivate Sub Timer1_Timer()
GetCursorPos mPos
If mPos.x < 10 Then
Form2.Show
else
form2.visible=false
endif
End Sub
Option ExplicitPublic Type PointAPI
X As Long
Y As Long
End Type
Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Public mPos As PointAPIPublic Declare Function GetSystemMenu Lib "user32" (ByVal hwnd _
As Long, ByVal bRevert As Long) As Long
Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As _
Long, ByVal nPosition As Long, ByVal wFlags As Long) As LongPublic JsForm2 As Boolean ' Form2启动标记
Public JSQ As Integerform1:Option ExplicitPrivate Sub Form_Load()
Timer1.Interval = 60
End SubPrivate Sub Timer1_Timer()
GetCursorPos mPos
If mPos.X < 10 Then
Form2.Show
Else
Form2.Visible = False
End If
End Subform2:
不用代码
Private Sub Form_Load()(这一行黄底)
Timer1.Interval = 60(这一行前面Timer1兰底)
End Sub
请问如何更正.