📄 textcolor.vb
字号:
Me.label3.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold)
Me.label3.Location = New System.Drawing.Point(88, 128)
Me.label3.Size = New System.Drawing.Size(40, 20)
Me.label3.Text = "Red"
'
'label4
'
Me.label4.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold)
Me.label4.Location = New System.Drawing.Point(120, 128)
Me.label4.Size = New System.Drawing.Size(48, 20)
Me.label4.Text = "Green"
'
'label5
'
Me.label5.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold)
Me.label5.Location = New System.Drawing.Point(168, 128)
Me.label5.Size = New System.Drawing.Size(40, 20)
Me.label5.Text = "Blue"
'
'label1
'
Me.label1.Location = New System.Drawing.Point(36, 152)
Me.label1.Size = New System.Drawing.Size(40, 20)
Me.label1.Text = "Text:"
Me.label1.TextAlign = System.Drawing.ContentAlignment.TopRight
'
'label2
'
Me.label2.Location = New System.Drawing.Point(0, 176)
Me.label2.Size = New System.Drawing.Size(80, 20)
Me.label2.Text = "Background:"
Me.label2.TextAlign = System.Drawing.ContentAlignment.TopRight
'
'lblTextR
'
Me.lblTextR.Location = New System.Drawing.Point(88, 152)
Me.lblTextR.Size = New System.Drawing.Size(40, 20)
'
'lblTextG
'
Me.lblTextG.Location = New System.Drawing.Point(128, 152)
Me.lblTextG.Size = New System.Drawing.Size(40, 20)
'
'lblTextB
'
Me.lblTextB.Location = New System.Drawing.Point(168, 152)
Me.lblTextB.Size = New System.Drawing.Size(40, 20)
'
'lblBackR
'
Me.lblBackR.Location = New System.Drawing.Point(88, 176)
Me.lblBackR.Size = New System.Drawing.Size(40, 20)
'
'lblBackG
'
Me.lblBackG.Location = New System.Drawing.Point(128, 176)
Me.lblBackG.Size = New System.Drawing.Size(40, 20)
'
'lblBackB
'
Me.lblBackB.Location = New System.Drawing.Point(168, 176)
Me.lblBackB.Size = New System.Drawing.Size(40, 20)
'
'FormMain
'
Me.Controls.Add(Me.lblBackB)
Me.Controls.Add(Me.lblBackG)
Me.Controls.Add(Me.lblBackR)
Me.Controls.Add(Me.lblTextB)
Me.Controls.Add(Me.lblTextG)
Me.Controls.Add(Me.lblTextR)
Me.Controls.Add(Me.label2)
Me.Controls.Add(Me.label1)
Me.Controls.Add(Me.label5)
Me.Controls.Add(Me.label4)
Me.Controls.Add(Me.label3)
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular)
Me.Menu = Me.menuMain
Me.MinimizeBox = False
Me.Text = "TextColor"
End Sub
#End Region
Private Sub FormMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
DisplayRGBComponents()
End Sub
'
' Display color picker dialog -- foreground color
'
Private Sub mitemTextSetColor_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mitemTextSetColor.Click
Dim ccdlg As ChooseColorDlg = New ChooseColorDlg
ccdlg.Init(Me)
If ccdlg.ShowDialog(m_clrText) Then
Invalidate()
DisplayRGBComponents()
End If
End Sub
'
' Display color picker dialog -- background color
'
Private Sub mitemBackSetColor_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mitemBackSetColor.Click
Dim ccdlg As ChooseColorDlg = New ChooseColorDlg
ccdlg.Init(Me)
If ccdlg.ShowDialog(m_clrBack) Then
Invalidate()
DisplayRGBComponents()
End If
End Sub
' Private data
Dim m_clrBack As Color = SystemColors.Window
Dim m_clrText As Color = SystemColors.WindowText
Private Sub FormMain_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
Dim g As Graphics = e.Graphics
' The string to draw.
Dim strDraw As String = "Text Color"
' String location -- in floating point.
Dim sinX As Single = 10.0F
Dim sinY As Single = 10.0F
' Location as integers.
Dim x As Integer = CType(sinX, Integer)
Dim y As Integer = CType(sinY, Integer)
' Draw background if needed
If (Not m_clrBack.Equals(SystemColors.Window)) Then
' Calculate size of string bounding box.
Dim size As SizeF = g.MeasureString(strDraw, Font)
Dim cx As Integer = CType(size.Width, Integer)
Dim cy As Integer = CType(size.Height, Integer)
' Draw text bounding box.
Dim rc As Rectangle = New Rectangle(x, y, cx, cy)
Dim brBack As Brush = New SolidBrush(m_clrBack)
g.FillRectangle(brBack, rc)
brBack.Dispose()
End If
Dim brText As Brush = New SolidBrush(m_clrText)
g.DrawString(strDraw, Font, brText, sinX, sinY)
brText.Dispose()
End Sub
Private Sub DisplayRGBComponents()
Dim byt As Byte = m_clrText.R
lblTextR.Text = byt.ToString("000")
byt = m_clrText.G
lblTextG.Text = byt.ToString("000")
byt = m_clrText.B
lblTextB.Text = byt.ToString("000")
byt = m_clrBack.R
lblBackR.Text = byt.ToString("000")
byt = m_clrBack.G
lblBackG.Text = byt.ToString("000")
byt = m_clrBack.B
lblBackB.Text = byt.ToString("000")
End Sub
Private Sub SetTextColor(ByVal clr As Color)
m_clrText = clr
Invalidate()
DisplayRGBComponents()
End Sub
Private Sub SetBackColor(ByVal clr As Color)
m_clrBack = clr
Invalidate()
DisplayRGBComponents()
End Sub
Private Sub mitemTextControlText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextControlText.Click
SetTextColor(SystemColors.ControlText)
End Sub
Private Sub mitemTextGrayText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextGrayText.Click
SetTextColor(SystemColors.GrayText)
End Sub
Private Sub mitemTextHighlightText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextHighlightText.Click
SetTextColor(SystemColors.HighlightText)
End Sub
Private Sub mitemTextInfoText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextInfoText.Click
SetTextColor(SystemColors.InfoText)
End Sub
Private Sub mitemTextMenuText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextMenuText.Click
SetTextColor(SystemColors.MenuText)
End Sub
Private Sub mitemTextWindowText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextWindowText.Click
SetTextColor(SystemColors.WindowText)
End Sub
Private Sub mitemTextAliceBlue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextAliceBlue.Click
SetTextColor(Color.AliceBlue)
End Sub
Private Sub mitemTextBeige_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextBeige.Click
SetTextColor(Color.Beige)
End Sub
Private Sub mitemTextCoral_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextCoral.Click
SetTextColor(Color.Coral)
End Sub
Private Sub mitemTextDeepPink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextDeepPink.Click
SetTextColor(Color.DeepPink)
End Sub
Private Sub mitemTextFireBrick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextFireBrick.Click
SetTextColor(Color.Firebrick)
End Sub
Private Sub mitemTextGainsboro_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextGainsboro.Click
SetTextColor(Color.Gainsboro)
End Sub
Private Sub mitemTextHoneyDew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemTextHoneyDew.Click
SetTextColor(Color.Honeydew)
End Sub
Private Sub mitemBackControl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackControl.Click
SetBackColor(SystemColors.Control)
End Sub
Private Sub mitemBackHighlight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackHighlight.Click
SetBackColor(SystemColors.Highlight)
End Sub
Private Sub mitemBackInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackInfo.Click
SetBackColor(SystemColors.Info)
End Sub
Private Sub mitemBackMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackMenu.Click
SetBackColor(SystemColors.Menu)
End Sub
Private Sub mitemBackWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackWindow.Click
SetBackColor(SystemColors.Window)
End Sub
Private Sub mitemBackIndigo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackIndigo.Click
SetBackColor(Color.Indigo)
End Sub
Private Sub mitemBackKhaki_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackKhaki.Click
SetBackColor(Color.Khaki)
End Sub
Private Sub mitemBackLavendar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackLavendar.Click
SetBackColor(Color.Lavender)
End Sub
Private Sub mitemBackMagenta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackMagenta.Click
SetBackColor(Color.Magenta)
End Sub
Private Sub mitemBackNavy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackNavy.Click
SetBackColor(Color.Navy)
End Sub
Private Sub mitemBackOlive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackOlive.Click
SetBackColor(Color.Olive)
End Sub
Private Sub mitemBackPlum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mitemBackPlum.Click
SetBackColor(Color.Plum)
End Sub
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -