📄 messagebox.vb
字号:
.Location = New Point(8, 32)
.BackColor = Color.Transparent
.BorderStyle = BorderStyle.None
.SendToBack()
.Visible = True
End With
End Sub
Private Shared Sub CreateMeaasge()
WinMessage = New Label()
With WinMessage
.Text = ""
.Size = New Size(MsgWidth, MsgHeight)
.Location = New Point(48, 32)
.AutoSize = False
.Font = WinFnt
.TextAlign = ContentAlignment.TopLeft
.BackColor = Color.Transparent
.SendToBack()
.Visible = True
End With
End Sub
Private Shared Sub AddToBaseScreen()
With WinMsg
.Controls.Add(LblHeader)
.Controls.Add(PicIcon)
.Controls.Add(WinMessage)
.Refresh()
End With
End Sub
Private Shared Sub CreateMessageButtons(ByVal WinButtons As MessageBoxButtons)
Select Case WinButtons
Case MessageBoxButtons.AbortRetryIgnore
If FormWidth <= 305 And FormHeight <= 135 Then
CmdAbort = New Button()
Call ButtonProperties(CmdAbort, "Abort", New Size(56, 24), New Point(FormWidth - (90 * 2), FormHeight - 65))
CmdRetry = New Button()
Call ButtonProperties(CmdRetry, "Retry", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdIgnore = New Button()
Call ButtonProperties(CmdIgnore, "Ignore", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
Else
If FormWidth > 305 And FormHeight <= 135 Then
CmdAbort = New Button()
Call ButtonProperties(CmdAbort, "Abort", New Size(56, 24), New Point(FormWidth - (90 * 2), FormHeight - 65))
CmdRetry = New Button()
Call ButtonProperties(CmdRetry, "Retry", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdIgnore = New Button()
Call ButtonProperties(CmdIgnore, "Ignore", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
If FormWidth >= 305 And FormHeight >= 135 Then
CmdAbort = New Button()
Call ButtonProperties(CmdAbort, "Abort", New Size(56, 24), New Point(FormWidth - (90 * 2), FormHeight - 65))
CmdRetry = New Button()
Call ButtonProperties(CmdRetry, "Retry", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdIgnore = New Button()
Call ButtonProperties(CmdIgnore, "Ignore", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
End If
Case MessageBoxButtons.OK
If FormWidth <= 305 And FormHeight <= 135 Then
CmdOk = New Button()
Call ButtonProperties(CmdOk, "Ok", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
Else
If FormWidth >= 305 And FormHeight <= 135 Then
CmdOk = New Button()
Call ButtonProperties(CmdOk, "Ok", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
If FormWidth >= 305 And FormHeight >= 135 Then
CmdOk = New Button()
Call ButtonProperties(CmdOk, "Ok", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
End If
Case MessageBoxButtons.OKCancel
If FormWidth <= 305 And FormHeight <= 135 Then
CmdOk = New Button()
Call ButtonProperties(CmdOk, "Ok", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdCancel = New Button()
Call ButtonProperties(CmdCancel, "Cancel", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
Else
If FormWidth > 305 And FormHeight <= 135 Then
CmdOk = New Button()
Call ButtonProperties(CmdOk, "Ok", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdCancel = New Button()
Call ButtonProperties(CmdCancel, "Cancel", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
If FormWidth >= 305 And FormHeight >= 135 Then
CmdOk = New Button()
Call ButtonProperties(CmdOk, "Ok", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdCancel = New Button()
Call ButtonProperties(CmdCancel, "Cancel", New Size(56, 24), New Point(FormWidth - 70, FormHeight - FormHeight - 65))
Exit Select
End If
End If
Case MessageBoxButtons.RetryCancel
If FormWidth <= 305 And FormHeight <= 135 Then
CmdRetry = New Button()
Call ButtonProperties(CmdRetry, "Retry", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdCancel = New Button()
Call ButtonProperties(CmdCancel, "Cancel", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
Else
If FormWidth >= 305 And FormHeight <= 135 Then
CmdRetry = New Button()
Call ButtonProperties(CmdRetry, "Retry", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdCancel = New Button()
Call ButtonProperties(CmdCancel, "Cancel", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
If FormWidth >= 305 And FormHeight >= 135 Then
CmdRetry = New Button()
Call ButtonProperties(CmdRetry, "Retry", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdCancel = New Button()
Call ButtonProperties(CmdCancel, "Cancel", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
End If
Case MessageBoxButtons.YesNo
If FormWidth <= 305 And FormHeight <= 135 Then
CmdYes = New Button()
Call ButtonProperties(CmdYes, "Yes", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdNo = New Button()
Call ButtonProperties(CmdNo, "No", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
Else
If FormWidth >= 305 And FormHeight <= 135 Then
CmdYes = New Button()
Call ButtonProperties(CmdYes, "Yes", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdNo = New Button()
Call ButtonProperties(CmdNo, "No", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
If FormWidth >= 225 And FormHeight >= 135 Then
CmdYes = New Button()
Call ButtonProperties(CmdYes, "Yes", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdNo = New Button()
Call ButtonProperties(CmdNo, "No", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
End If
Case MessageBoxButtons.YesNoCancel
If FormWidth <= 305 And FormHeight <= 135 Then
CmdYes = New Button()
Call ButtonProperties(CmdYes, "Yes", New Size(56, 24), New Point(FormWidth - (90 * 2), FormHeight - 65))
CmdNo = New Button()
Call ButtonProperties(CmdNo, "No", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdCancel = New Button()
Call ButtonProperties(CmdCancel, "Cancel", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
Else
If FormWidth >= 305 And FormHeight <= 135 Then
CmdYes = New Button()
Call ButtonProperties(CmdYes, "Yes", New Size(56, 24), New Point(FormWidth - (90 * 2), FormHeight - 65))
CmdNo = New Button()
Call ButtonProperties(CmdNo, "No", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdCancel = New Button()
Call ButtonProperties(CmdCancel, "Cancel", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
If FormWidth >= 305 And FormHeight >= 135 Then
CmdYes = New Button()
Call ButtonProperties(CmdYes, "Yes", New Size(56, 24), New Point(FormWidth - (90 * 2), FormHeight - 65))
CmdNo = New Button()
Call ButtonProperties(CmdNo, "No", New Size(56, 24), New Point(FormWidth - (62.5 * 2), FormHeight - 65))
CmdCancel = New Button()
Call ButtonProperties(CmdCancel, "Cancel", New Size(56, 24), New Point(FormWidth - 70, FormHeight - 65))
Exit Select
End If
End If
End Select
End Sub
Private Shared Sub ButtonProperties(ByVal Btn As Button, ByVal Txt As String, ByVal Sz As Size, ByVal Lc As Point)
With Btn
.BringToFront()
.Size = Sz
.Text = Txt
.BackColor = Color.Transparent
.FlatAppearance.BorderSize = 0
.FlatStyle = FlatStyle.Standard
.Location = Lc
.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
.TextAlign = ContentAlignment.MiddleCenter
.Font = New Font("Consolas", 8, FontStyle.Regular)
.Visible = True
End With
WinMsg.Controls.Add(Btn)
End Sub
Private Shared Function StringSize(ByVal WinMsgText As String, _
ByVal WinWdth As Integer, _
ByVal WinFnt As Font) As Size
Dim GRA As Graphics = WinMsg.CreateGraphics()
Dim SZF As SizeF = GRA.MeasureString(WinMsgText, WinFnt, WinWdth)
GRA.Dispose()
Dim SZ As New Size(DirectCast(Convert.ToInt16(SZF.Width + 100), Int16), _
DirectCast(Convert.ToInt16(SZF.Height), Int16))
Return SZ
End Function
Private Shared Sub WinMsg_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles WinMsg.Paint
Dim MGraphics As Graphics = e.Graphics
Dim MPen As New Pen(Color.FromArgb(96, 155, 173), 1)
Dim Area As New Rectangle(0, 0, WinMsg.Width - 1, WinMsg.Height - 1)
Dim LGradient As New LinearGradientBrush(Area, Color.FromArgb(166, 197, 227), Color.FromArgb(245, 251, 251), LinearGradientMode.BackwardDiagonal)
MGraphics.CompositingMode = CompositingMode.SourceOver
MGraphics.CompositingQuality = CompositingQuality.HighQuality
MGraphics.FillRectangle(LGradient, Area)
MGraphics.DrawRectangle(MPen, Area)
End Sub
Private Shared Sub LblHeader_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LblHeader.MouseDown
WinLocation = e.Location
End Sub
Private Shared Sub LblHeader_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LblHeader.MouseMove
If String.Compare(Control.MouseButtons.ToString(), "Left") = 0 Then
Dim MSize As New Size(WinLocation)
MSize.Width = e.X - WinLocation.X
MSize.Height = e.Y - WinLocation.Y
WinMsg.Location = Point.Add(WinMsg.Location, MSize)
End If
End Sub
Private Shared Sub LblHeader_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles LblHeader.Paint
Dim MGraphics As Graphics = e.Graphics
Dim MPen As New Pen(Color.FromArgb(96, 155, 173), 1)
Dim Area As New Rectangle(0, 0, LblHeader.Width - 1, LblHeader.Height - 1)
Dim LGradient As New LinearGradientBrush(Area, Color.FromArgb(166, 197, 227), Color.FromArgb(245, 251, 251), LinearGradientMode.BackwardDiagonal)
MGraphics.CompositingMode = CompositingMode.SourceOver
MGraphics.CompositingQuality = CompositingQuality.HighQuality
MGraphics.FillRectangle(LGradient, Area)
MGraphics.DrawRectangle(MPen, Area)
Dim DrawFont As New Font("Consolas", 10, FontStyle.Regular)
Dim DrawBrush As New SolidBrush(Color.Black)
Dim DrawPoint As New PointF(2.0F, 3.0F)
Dim DrawGradientBrush As New LinearGradientBrush(e.Graphics.ClipBounds, Color.White, _
Color.FromArgb(122, 158, 226), LinearGradientMode.ForwardDiagonal)
e.Graphics.CompositingMode = CompositingMode.SourceOver
e.Graphics.CompositingQuality = CompositingQuality.HighQuality
e.Graphics.DrawString(HeaderText.ToString(), DrawFont, DrawBrush, DrawPoint)
End Sub
Private Shared Sub CmdAbort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdAbort.Click
WinMsg.Dispose() : WinMsg = Nothing
WinMake = DialogResult.Abort
End Sub
Private Shared Sub CmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdCancel.Click
WinMsg.Dispose() : WinMsg = Nothing
WinMake = DialogResult.Cancel
End Sub
Private Shared Sub CmdIgnore_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdIgnore.Click
WinMsg.Dispose() : WinMsg = Nothing
WinMake = DialogResult.Ignore
End Sub
Private Shared Sub CmdNo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdNo.Click
WinMsg.Dispose() : WinMsg = Nothing
WinMake = DialogResult.No
End Sub
Private Shared Sub CmdOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdOk.Click
WinMsg.Dispose() : WinMsg = Nothing
WinMake = DialogResult.OK
End Sub
Private Shared Sub CmdRetry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdRetry.Click
WinMsg.Dispose() : WinMsg = Nothing
WinMake = DialogResult.Retry
End Sub
Private Shared Sub CmdYes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdYes.Click
WinMsg.Dispose() : WinMsg = Nothing
WinMake = DialogResult.Yes
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -