📄 frmmsg.vb
字号:
Imports System.Windows.Forms
Friend Class frmMsg
Inherits System.Windows.Forms.Form
Enum ShowStatus
ssShow
ssWait
ssHide
ssDone
End Enum
Private m_ShowStatus As ShowStatus '当前装态,show, wait, hide
'内部一个周期的参数
Protected m_iShowSpeed As Integer = 6 '出现速度
Private m_iHideSpeed As Integer = 6 '隐藏速度
Private m_iWaitTime As Integer = 50 * 100.0 / 30 '等待时间
'多个周期所需的参数
Private m_bOnlyOnce As Boolean = False '默认反复出现
Private m_iInterval As Integer = 10 '10秒
'循环计数器
Private m_iRestartIndex As Integer
Private m_iIndex As Long
Private m_iHeight As Integer
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents labMsg As System.Windows.Forms.Label
Friend WithEvents timerRestart As System.Windows.Forms.Timer
Friend WithEvents timerControl As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.labMsg = New System.Windows.Forms.Label
Me.timerControl = New System.Windows.Forms.Timer(Me.components)
Me.timerRestart = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
'
'labMsg
'
Me.labMsg.BackColor = System.Drawing.Color.Transparent
Me.labMsg.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.labMsg.ForeColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(0, Byte), CType(0, Byte))
Me.labMsg.Location = New System.Drawing.Point(16, 16)
Me.labMsg.Name = "labMsg"
Me.labMsg.Size = New System.Drawing.Size(168, 88)
Me.labMsg.TabIndex = 0
Me.labMsg.Text = "技术支持:http://www.trfsoft.com"
'
'timerControl
'
Me.timerControl.Interval = 30
'
'timerRestart
'
Me.timerRestart.Interval = 1000
'
'frmMsg
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackColor = System.Drawing.SystemColors.Desktop
Me.ClientSize = New System.Drawing.Size(200, 120)
Me.ControlBox = False
Me.Controls.Add(Me.labMsg)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "frmMsg"
Me.ShowInTaskbar = False
Me.Text = "TrayMsg"
Me.TopMost = True
Me.ResumeLayout(False)
End Sub
#End Region
'处理一个周期:弹出---等待---隐藏
Private Sub timerCtrol_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerControl.Tick
Select Case m_ShowStatus
Case ShowStatus.ssShow
If Me.Top > Screen.PrimaryScreen.WorkingArea.Bottom - Me.Height Then
' If Me.Height < m_iHeight Then
Me.SuspendLayout()
Me.Top -= m_iShowSpeed
'Me.Height += m_iShowSpeed
Me.ResumeLayout()
Else
m_ShowStatus = ShowStatus.ssWait
End If
Case ShowStatus.ssWait
If m_iIndex < m_iWaitTime Then
m_iIndex += 1
Else
m_iIndex = 0
m_ShowStatus = ShowStatus.ssHide
End If
Case ShowStatus.ssHide
If Me.Top < Screen.PrimaryScreen.Bounds.Bottom Then
'If Me.Top < Screen.PrimaryScreen.Bounds.Bottom Then
Me.Top += m_iHideSpeed
'Me.Height -= m_iHideSpeed
Else
m_ShowStatus = ShowStatus.ssDone
End If
Case ShowStatus.ssDone
m_iRestartIndex = 0
timerControl.Enabled = False
If m_bOnlyOnce = False Then
timerRestart.Enabled = True
End If
End Select
End Sub
'等待触发下一周期
Private Sub timerRestart_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerRestart.Tick
If m_iRestartIndex < m_iInterval Then
m_iRestartIndex += 1
Else
ReStart()
End If
End Sub
'初始化内部参数
Private Sub InitDefaultInternalPara()
m_iShowSpeed = 6
m_iHideSpeed = 8
m_iWaitTime = 50 * 100.0 / timerControl.Interval
End Sub
'开始新的一轮弹出--等待--隐藏
Private Sub ReStart()
'初始状态
Me.Left = Screen.PrimaryScreen.WorkingArea.Right - Me.Width - 10
Me.Top = Screen.PrimaryScreen.WorkingArea.Bottom
'Me.Height = 0
m_iIndex = 0
m_iRestartIndex = 0
m_ShowStatus = ShowStatus.ssShow
timerRestart.Enabled = False
timerControl.Enabled = True
End Sub
'==================================================================================
'ShowSpeed: 显示消息框速度,取值1-10,数越大越快
'WaitTime: 默认停留时间,以0.1秒为单位
'HideSpeed: 隐藏速度,取值1-10,数越大越快
'==================================================================================
Public Function CreateWnd(Optional ByVal ShowSpeed As Integer = 4, _
Optional ByVal WaitTime As Integer = 4, _
Optional ByVal HideSpeed As Integer = 6) As String
If ShowSpeed < 1 Or ShowSpeed > 10 Then
Return "the ShowSpeed should be between 1 to 10"
End If
If WaitTime > 99999 Then
Return "the WaitTime should be less than 99999, " + vbLf + "if it is equal or less than 0, the msg will be shown forever"
End If
If HideSpeed < 1 Or HideSpeed > 10 Then
Return "the HideSpeed should be between 1 to 10"
End If
m_iShowSpeed = ShowSpeed
m_iWaitTime = WaitTime * 100.0 / 30
m_iHideSpeed = HideSpeed
'创建成功
Return ""
End Function
'==================================================================================
'OnlyOnce: 是否只显示一次
'Interval: 下次显示的间隔时间,以秒为单位
'==================================================================================
Public Function ShowWnd(Optional ByVal OnlyOnce As Boolean = True, _
Optional ByVal Interval As Integer = 10) As String
m_bOnlyOnce = OnlyOnce
m_iInterval = Interval
Me.Show()
'开始运行
ReStart()
Return ""
End Function
Private Sub frmMsg_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim rect As System.Drawing.Rectangle
Dim color1, color2 As System.Drawing.Color
rect = rect.FromLTRB(0, 0, Me.Width, Me.Height)
color1 = System.Drawing.Color.FromArgb(80, 150, 250)
color2 = System.Drawing.Color.White
Dim lnBrush As New System.Drawing.Drawing2D.LinearGradientBrush(rect, color1, color2, Drawing.Drawing2D.LinearGradientMode.Vertical)
e.Graphics.FillRectangle(lnBrush, rect)
End Sub
Private Sub frmMsg_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
m_ShowStatus = ShowStatus.ssHide
m_bOnlyOnce = True
End Sub
Private Sub frmMsg_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_iHeight = Me.Height
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -