📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
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
Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog
Friend WithEvents bttnCentered As System.Windows.Forms.Button
Friend WithEvents bttnSemiTransparent As System.Windows.Forms.Button
Friend WithEvents bttnBoxed As System.Windows.Forms.Button
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.bttnCentered = New System.Windows.Forms.Button()
Me.bttnSemiTransparent = New System.Windows.Forms.Button()
Me.bttnBoxed = New System.Windows.Forms.Button()
Me.FontDialog1 = New System.Windows.Forms.FontDialog()
Me.SuspendLayout()
'
'bttnCentered
'
Me.bttnCentered.BackColor = System.Drawing.SystemColors.Control
Me.bttnCentered.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnCentered.Location = New System.Drawing.Point(656, 8)
Me.bttnCentered.Name = "bttnCentered"
Me.bttnCentered.Size = New System.Drawing.Size(216, 32)
Me.bttnCentered.TabIndex = 4
Me.bttnCentered.Text = "Draw Centered String"
'
'bttnSemiTransparent
'
Me.bttnSemiTransparent.BackColor = System.Drawing.SystemColors.Control
Me.bttnSemiTransparent.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnSemiTransparent.Location = New System.Drawing.Point(8, 8)
Me.bttnSemiTransparent.Name = "bttnSemiTransparent"
Me.bttnSemiTransparent.Size = New System.Drawing.Size(216, 32)
Me.bttnSemiTransparent.TabIndex = 0
Me.bttnSemiTransparent.Text = "Draw Semi-Transparent Text"
'
'bttnBoxed
'
Me.bttnBoxed.BackColor = System.Drawing.SystemColors.Control
Me.bttnBoxed.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnBoxed.Location = New System.Drawing.Point(332, 8)
Me.bttnBoxed.Name = "bttnBoxed"
Me.bttnBoxed.Size = New System.Drawing.Size(216, 32)
Me.bttnBoxed.TabIndex = 3
Me.bttnBoxed.Text = "Draw Boxed Text"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(19, 52)
Me.BackColor = System.Drawing.Color.Silver
Me.ClientSize = New System.Drawing.Size(880, 357)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.bttnCentered, Me.bttnBoxed, Me.bttnSemiTransparent})
Me.Font = New System.Drawing.Font("Pepita MT", 36!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "Form1"
Me.Text = "Text Effects"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub semiTransparent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnSemiTransparent.Click
Dim G As Graphics
Dim brush As SolidBrush
G = GetGraphicsObject()
G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
G.FillRectangle(New SolidBrush(Color.Silver), ClientRectangle)
Dim drawFont As Font
brush = New SolidBrush(Color.FromArgb(255, 0, 0, 255))
drawFont = New Font("Comic Sans MS", 72, Drawing.FontStyle.Bold)
G.DrawString("Visual Basic.NET", drawFont, brush, 10, 30)
brush.Color = Color.FromArgb(192, 0, 255, 255)
G.DrawString("Visual Basic.NET", drawFont, brush, 7, 27)
brush.Color = Color.FromArgb(255, 0, 0, 255)
drawFont = New Font("Comic Sans MS", 72, Drawing.FontStyle.Bold)
G.DrawString("Visual Basic.NET", drawFont, brush, 10, 130)
brush.Color = Color.FromArgb(128, 0, 255, 255)
G.DrawString("Visual Basic.NET", drawFont, brush, 7, 127)
brush.Color = Color.FromArgb(255, 128, 64, 255)
drawFont = New Font("Comic Sans MS", 72, Drawing.FontStyle.Bold)
G.DrawString("Visual Basic.NET", drawFont, brush, 10, 230)
brush.Color = Color.FromArgb(128, 255, 128, 64)
G.DrawString("Visual Basic.NET", drawFont, brush, 7, 227)
Me.Invalidate()
End Sub
Private Sub BoxedText(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnBoxed.Click
Dim G As Graphics
G = GetGraphicsObject()
G.FillRectangle(New SolidBrush(Color.Silver), ClientRectangle)
Dim txt As String = "This text was rendered in a rectangle with the DrawString method of the Form's Graphics object. "
txt = txt & txt & txt & txt & txt
G.DrawString(txt, New Font("verdana", 12, FontStyle.Regular), Brushes.Black, New RectangleF(100, 80, 180, 250))
G.DrawRectangle(Pens.Red, 100, 80, 180, 250)
G.DrawString(txt, New Font("verdana", 12, FontStyle.Regular), Brushes.Black, New RectangleF(350, 100, 400, 150))
G.DrawRectangle(Pens.Red, 350, 100, 400, 150)
Me.Invalidate()
End Sub
Private Sub center(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnCentered.Click
Dim G As Graphics
G = GetGraphicsObject()
G.FillRectangle(New SolidBrush(Color.Silver), ClientRectangle)
G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
FontDialog1.Font = Me.Font
FontDialog1.ShowDialog()
Dim txtFont As Font
txtFont = FontDialog1.Font
G.DrawLine(New Pen(Color.Green), CInt(Me.Width / 2), CInt(0), CInt(Me.Width / 2), CInt(Me.Height))
G.DrawLine(New Pen(Color.Green), 0, CInt(Me.Height / 2), CInt(Me.Width), CInt(Me.Height / 2))
Dim txtLen, txtHeight As Integer
Dim txtSize As SizeF
txtSize = G.MeasureString("Visual Basic.NET", txtFont)
Dim txtX, txtY As Integer
txtX = (Me.Width - txtSize.Width) / 2
txtY = (Me.Height - txtSize.Height) / 2
G.DrawString("Visual Basic.NET", txtFont, New SolidBrush(Color.Red), txtX, txtY)
Dim boxSize As SizeF
boxSize = G.MeasureString("Visual Basic.NET", txtFont)
G.DrawRectangle(Pens.Black, txtX, txtY, boxSize.Width, boxSize.Height)
Me.Invalidate()
End Sub
Function GetGraphicsObject() As Graphics
Dim bmp As Bitmap
bmp = New Bitmap(Me.Width, Me.Height)
Dim G As Graphics
Me.BackgroundImage = bmp
G = Graphics.FromImage(bmp)
Return G
End Function
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -