![]() |
#2
hmj07452021-12-10 16:36
|
思路:提示窗显示后,让代码进入循环,当窗体点击后产生变量后跳出,由此得到交互和程序挂起的效果。
效果:能得到自己像要的提示窗效果,能从自己指定位置显示,两不是永远在屏幕中间(当你程序不处于最大化显示时,可能处于桌面其它位置时,提示却显示在屏中间这一点很难忍受)
这两天在网上找资料找烦了,基本上是垃圾代码!现在解决了就分享给我一样的初学者参考吧,大神略过。。。。。。。
*******上图*******************
只有本站会员才能查看附件,请 登录
******************************
只有本站会员才能查看附件,请 登录
*******上附件****************
只有本站会员才能查看附件,请 登录
*******模块中代码******************

Public Msgmod, Str As String
Public MsgYN As Boolean, IsExit As Boolean
Public Frmleft As Long, Frmtop As Long
Sub Main()
Form1.Show 0
End Sub
'01函数名: Msgfrm
'函数功能: 自定义消息框,文字内容,输入模式,和边距
'*****************************************************************************************
Function Msgfrm(Str As String, Md As Byte, FrmLe As Long, FrmTo As Long)
Msgmod = Md '//窗体模式
Frmleft = FrmLe '//窗体出现的左边距
Frmtop = FrmTo '//窗体出现的顶边距
Str = Str '//窗体显示的提示文字
Rem 以上把传入的参赋值给窗体*****************************************
Msgfm.Show 0
IsExit = False '全局变量
Do While DoEvents '// 设置一个循环直到交出控制权
If IsExit = True Then Exit Do '// 当全局变量为 True 时跳出循环
Loop
Msgfrm = MsgYN
End Function
Public MsgYN As Boolean, IsExit As Boolean
Public Frmleft As Long, Frmtop As Long
Sub Main()
Form1.Show 0
End Sub
'01函数名: Msgfrm
'函数功能: 自定义消息框,文字内容,输入模式,和边距
'*****************************************************************************************
Function Msgfrm(Str As String, Md As Byte, FrmLe As Long, FrmTo As Long)
Msgmod = Md '//窗体模式
Frmleft = FrmLe '//窗体出现的左边距
Frmtop = FrmTo '//窗体出现的顶边距
Str = Str '//窗体显示的提示文字
Rem 以上把传入的参赋值给窗体*****************************************
Msgfm.Show 0
IsExit = False '全局变量
Do While DoEvents '// 设置一个循环直到交出控制权
If IsExit = True Then Exit Do '// 当全局变量为 True 时跳出循环
Loop
Msgfrm = MsgYN
End Function
*******提示窗体中代码*******************************************************

Option Explicit
Private Sub Form_Deactivate() '//不在当前时主动卸载自己,避免多窗体冲突
IsExit = True
Unload Me
End Sub
Private Sub Form_Load()
Me.Move Frmleft, Frmtop ' 移动到指定位
'*****下面是窗体外观的一些调整设计
Shape1.BackColor = RGB(0, 178, 250)
Shape2.BorderColor = RGB(0, 178, 250)
Shape1.Move 0, 0, 4020, 400
Shape2.Move 0, 390, 4000, 2150
Label2.Move 0, 150, 4000, 200
'**********************************
Label1.Move 900, 900, 2900, 1200
Pic1.Move 100, 600, 600, 550
Pic2.Move 100, 600, 600, 550
'两种模式的切换,显示不同的按钮和图标*****************************
If Msgmod = 1 Then
Pic1.Visible = True
Me.确认.Visible = True
Label2.Caption = "******系统警告!******"
Else
Pic2.Visible = True
Me.是.Visible = True
Me.否.Visible = True
Label2.Caption = "******系统提示!******"
End If
Label1 = Str
End Sub
Private Sub 确认_Click()
MsgYN = True
IsExit = True
Unload Me
End Sub
Private Sub 是_Click()
IsExit = True
MsgYN = True
Unload Me
End Sub
Private Sub 否_Click()
IsExit = True
MsgYN = False
Unload Me
End Sub
Private Sub Form_Deactivate() '//不在当前时主动卸载自己,避免多窗体冲突
IsExit = True
Unload Me
End Sub
Private Sub Form_Load()
Me.Move Frmleft, Frmtop ' 移动到指定位
'*****下面是窗体外观的一些调整设计
Shape1.BackColor = RGB(0, 178, 250)
Shape2.BorderColor = RGB(0, 178, 250)
Shape1.Move 0, 0, 4020, 400
Shape2.Move 0, 390, 4000, 2150
Label2.Move 0, 150, 4000, 200
'**********************************
Label1.Move 900, 900, 2900, 1200
Pic1.Move 100, 600, 600, 550
Pic2.Move 100, 600, 600, 550
'两种模式的切换,显示不同的按钮和图标*****************************
If Msgmod = 1 Then
Pic1.Visible = True
Me.确认.Visible = True
Label2.Caption = "******系统警告!******"
Else
Pic2.Visible = True
Me.是.Visible = True
Me.否.Visible = True
Label2.Caption = "******系统提示!******"
End If
Label1 = Str
End Sub
Private Sub 确认_Click()
MsgYN = True
IsExit = True
Unload Me
End Sub
Private Sub 是_Click()
IsExit = True
MsgYN = True
Unload Me
End Sub
Private Sub 否_Click()
IsExit = True
MsgYN = False
Unload Me
End Sub