VB.Net/2D/Color

Материал из VB Эксперт
Перейти к: навигация, поиск

Color Dialog: Changing the background and text colors of a form

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class MainClass
   Shared Sub Main()
        Dim myform As Form = New FrmColorDialogTest()
        Application.Run(myform)
   End Sub " Main
End Class

Public Class FrmColorDialogTest
   Inherits System.Windows.Forms.Form
   Friend WithEvents cmdBackgroundButton As Button
   Friend WithEvents cmdTextButton As Button
#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
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.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.cmdBackgroundButton = New System.Windows.Forms.Button()
      Me.cmdTextButton = New System.Windows.Forms.Button()
      Me.SuspendLayout()
      "
      "cmdBackgroundButton
      "
      Me.cmdBackgroundButton.Location = New System.Drawing.Point(16, 16)
      Me.cmdBackgroundButton.Name = "cmdBackgroundButton"
      Me.cmdBackgroundButton.Size = New System.Drawing.Size(160, 24)
      Me.cmdBackgroundButton.TabIndex = 0
      Me.cmdBackgroundButton.Text = "Change Background Color"
      "
      "cmdTextButton
      "
      Me.cmdTextButton.Location = New System.Drawing.Point(16, 56)
      Me.cmdTextButton.Name = "cmdTextButton"
      Me.cmdTextButton.Size = New System.Drawing.Size(160, 24)
      Me.cmdTextButton.TabIndex = 1
      Me.cmdTextButton.Text = "Change Text Color"
      "
      "FrmColorDialogTest
      "
      Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
      Me.ClientSize = New System.Drawing.Size(192, 93)
      Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdTextButton, Me.cmdBackgroundButton})
      Me.Name = "FrmColorDialogTest"
      Me.Text = "Using Color Dialogs"
      Me.ResumeLayout(False)
   End Sub
#End Region
   Private Sub cmdTextButton_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles cmdTextButton.Click
      Dim colorBox As ColorDialog = New ColorDialog()
      Dim result As DialogResult
      result = colorBox.ShowDialog()
      If result = DialogResult.Cancel Then
         Return
      End If
      cmdBackgroundButton.ForeColor = colorBox.Color
      cmdTextButton.ForeColor = colorBox.Color
   End Sub 
   Private Sub cmdBackgroundButton_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles cmdBackgroundButton.Click
      Dim colorBox As ColorDialog = New ColorDialog()
      Dim result As DialogResult
      colorBox.FullOpen = True
      result = colorBox.ShowDialog()
      If result = DialogResult.Cancel Then
         Return
      End If
      Me.BackColor = colorBox.Color
   End Sub  
End Class


Construct Color from R G B Value

Imports System
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class MainClass
    Shared Sub Main()
        Dim myform As Form = New DrawingForm()
        Application.Run(myform)
    End Sub
End Class

Public Class DrawingForm
    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
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "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.
    Friend WithEvents drawEllipseButton As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.drawEllipseButton = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        "
        "drawEllipseButton
        "
        Me.drawEllipseButton.Location = New System.Drawing.Point(43, 32)
        Me.drawEllipseButton.Name = "drawEllipseButton"
        Me.drawEllipseButton.TabIndex = 1
        Me.drawEllipseButton.Text = "Draw Ellipse"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(160, 86)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.drawEllipseButton})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Dim drawEllipse As Boolean = False
    Private Sub drawEllipseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drawEllipseButton.Click
        drawEllipse = Not drawEllipse
        Me.Refresh()
    End Sub
    Private Sub DrawingForm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
        Dim blue25PercentOpaque As Color = Color.FromArgb(255 * 1 / 4, 0, 0, 255)
        Dim blue75PercentOpaque As Color = Color.FromArgb(-1090518785)
        Dim white As Color = Color.FromArgb(255, 255, 255)
        Dim black As Color = Color.FromArgb(0, 0, 0)
        Dim blue1 As Color = Color.BlueViolet
        Dim blue2 As Color = Color.FromKnownColor(KnownColor.ActiveBorder)
        Dim blue3 As Color = Color.FromName("ActiveBorder")
        Dim htmlBlue As Color = ColorTranslator.FromHtml("#0000ff")
        If Not drawEllipse Then Return
        Dim g As Graphics = e.Graphics
        Dim b As Brush = New SolidBrush(blue25PercentOpaque)
        g.FillEllipse(b, Me.ClientRectangle)
    End Sub
End Class


Get all Known color and calcuate its Brightness and Saturation

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.IO

public class MainClass
   Shared Sub Main()
      Dim form1 As Form = New Form1
      Application.Run(form1)
   End Sub
End Class


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
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "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.
    Friend WithEvents lstColors As System.Windows.Forms.ListBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents lblBrightness As System.Windows.Forms.Label
    Friend WithEvents lblHue As System.Windows.Forms.Label
    Friend WithEvents lblSaturation As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.lstColors = New System.Windows.Forms.ListBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.lblBrightness = New System.Windows.Forms.Label()
        Me.lblHue = New System.Windows.Forms.Label()
        Me.lblSaturation = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        "
        "lstColors
        "
        Me.lstColors.Location = New System.Drawing.Point(12, 40)
        Me.lstColors.Name = "lstColors"
        Me.lstColors.Size = New System.Drawing.Size(200, 238)
        Me.lstColors.TabIndex = 0
        "
        "Label1
        "
        Me.Label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Label1.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.Label1.Location = New System.Drawing.Point(12, 12)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(200, 20)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = " Choose a Background Color:"
        "
        "lblBrightness
        "
        Me.lblBrightness.BackColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.lblBrightness.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblBrightness.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.lblBrightness.Location = New System.Drawing.Point(268, 12)
        Me.lblBrightness.Name = "lblBrightness"
        Me.lblBrightness.Size = New System.Drawing.Size(136, 20)
        Me.lblBrightness.TabIndex = 2
        Me.lblBrightness.Text = " Brightness"
        "
        "lblHue
        "
        Me.lblHue.BackColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.lblHue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblHue.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.lblHue.Location = New System.Drawing.Point(268, 36)
        Me.lblHue.Name = "lblHue"
        Me.lblHue.Size = New System.Drawing.Size(136, 20)
        Me.lblHue.TabIndex = 3
        Me.lblHue.Text = " Hue"
        "
        "lblSaturation
        "
        Me.lblSaturation.BackColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.lblSaturation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblSaturation.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.lblSaturation.Location = New System.Drawing.Point(268, 60)
        Me.lblSaturation.Name = "lblSaturation"
        Me.lblSaturation.Size = New System.Drawing.Size(136, 20)
        Me.lblSaturation.TabIndex = 4
        Me.lblSaturation.Text = " Saturation"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(436, 294)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblSaturation, Me.lblHue, Me.lblBrightness, Me.Label1, Me.lstColors})
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "Form1"
        Me.Text = "Color Changer"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ColorNames() As String
        ColorNames = System.Enum.GetNames(GetType(KnownColor))
        lstColors.Items.AddRange(ColorNames)
    End Sub
    Private Sub lstColors_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstColors.SelectedIndexChanged
        Dim SelectedColor As KnownColor
        SelectedColor = System.Enum.Parse(GetType(KnownColor), lstColors.Text)
        Me.BackColor = System.Drawing.Color.FromKnownColor(SelectedColor)
        lblBrightness.Text = " Brightness = " & Me.BackColor.GetBrightness.ToString()
        lblHue.Text = " Hue = " & Me.BackColor.GetHue.ToString()
        lblSaturation.Text = " Saturation = " & Me.BackColor.GetSaturation.ToString()
    End Sub
End Class


Track Form background Color

Imports System.Windows.Forms
Imports System.Drawing

Module Module1
    Sub Main()
        Application.Run(New Form1)
    End Sub
End Module

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
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "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.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar
    Friend WithEvents TrackBar2 As System.Windows.Forms.TrackBar
    Friend WithEvents TrackBar3 As System.Windows.Forms.TrackBar
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.TrackBar1 = New System.Windows.Forms.TrackBar()
        Me.TrackBar2 = New System.Windows.Forms.TrackBar()
        Me.TrackBar3 = New System.Windows.Forms.TrackBar()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        CType(Me.TrackBar1, System.ruponentModel.ISupportInitialize).BeginInit()
        CType(Me.TrackBar2, System.ruponentModel.ISupportInitialize).BeginInit()
        CType(Me.TrackBar3, System.ruponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        "
        "Label1
        "
        Me.Label1.Location = New System.Drawing.Point(20, 30)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(56, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Red"
        "
        "TrackBar1
        "
        Me.TrackBar1.Location = New System.Drawing.Point(80, 30)
        Me.TrackBar1.Maximum = 255
        Me.TrackBar1.Name = "TrackBar1"
        Me.TrackBar1.Size = New System.Drawing.Size(180, 34)
        Me.TrackBar1.TabIndex = 2
        Me.TrackBar1.TickFrequency = 25
        "
        "TrackBar2
        "
        Me.TrackBar2.Location = New System.Drawing.Point(80, 80)
        Me.TrackBar2.Maximum = 255
        Me.TrackBar2.Name = "TrackBar2"
        Me.TrackBar2.Size = New System.Drawing.Size(180, 34)
        Me.TrackBar2.TabIndex = 5
        Me.TrackBar2.TickFrequency = 25
        "
        "TrackBar3
        "
        Me.TrackBar3.Location = New System.Drawing.Point(80, 130)
        Me.TrackBar3.Maximum = 255
        Me.TrackBar3.Name = "TrackBar3"
        Me.TrackBar3.Size = New System.Drawing.Size(180, 34)
        Me.TrackBar3.TabIndex = 3
        Me.TrackBar3.TickFrequency = 25
        "
        "Label2
        "
        Me.Label2.Location = New System.Drawing.Point(20, 80)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 23)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "Green"
        "
        "Label3
        "
        Me.Label3.Location = New System.Drawing.Point(20, 130)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(56, 23)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "Blue"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.Label2, Me.TrackBar3, Me.TrackBar2, Me.TrackBar1, Me.Label1})
        Me.Name = "Form1"
        Me.Text = "TrackBarDemo"
        CType(Me.TrackBar1, System.ruponentModel.ISupportInitialize).EndInit()
        CType(Me.TrackBar2, System.ruponentModel.ISupportInitialize).EndInit()
        CType(Me.TrackBar3, System.ruponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
    End Sub
#End Region
    Public Red As Byte
    Public Green As Byte
    Public Blue As Byte
    Public Background As Color
    Private Sub TrackBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
        Red = TrackBar1.Value
        Background = Color.FromArgb(Red, Green, Blue)
        RefreshBackground()
    End Sub

    Private Sub TrackBar2_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar2.ValueChanged
        Green = TrackBar2.Value
        Background = Color.FromArgb(Red, Green, Blue)
        
        RefreshBackground()
    End Sub

    Private Sub TrackBar3_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar3.ValueChanged
        Blue = TrackBar3.Value
        Background = Color.FromArgb(Red, Green, Blue)
        RefreshBackground()
    End Sub
    Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        Red = Form1.ActiveForm.BackColor.R
        Green = Form1.ActiveForm.BackColor.G
        Blue = Form1.ActiveForm.BackColor.B
        TrackBar1.Value = Red
        TrackBar2.Value = Green
        TrackBar3.Value = Blue
    End Sub
    Private Sub RefreshBackground()
        Form1.ActiveForm.BackColor = Background
        Form1.ActiveForm.Refresh()
    
    End Sub
End Class


Use color dialog to set form background

Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Printing

Public Class MainClass
    Shared Sub Main()
       Dim form1 As Form = New Form1()
       Application.Run(form1) 
    End Sub
End Class

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 btnColor As System.Windows.Forms.Button
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.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.btnColor = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        "
        "btnColor
        "
        Me.btnColor.Location = New System.Drawing.Point(54, 192)
        Me.btnColor.Name = "btnColor"
        Me.btnColor.Size = New System.Drawing.Size(184, 48)
        Me.btnColor.TabIndex = 0
        Me.btnColor.Text = "Change background color"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
        Me.ClientSize = New System.Drawing.Size(292, 268)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnColor})
        Me.Name = "Form1"
        Me.Text = "Color Dialog Example"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub btnColor_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnColor.Click
        Dim myDialog As New ColorDialog()
        Dim Temp As Color = btnColor.BackColor
        If myDialog.ShowDialog() = DialogResult.OK Then
            Me.BackColor = myDialog.Color
            btnColor.BackColor = Temp
        End If
    End Sub
End Class


Using different colors in Visual Basic

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class MainClass
   Shared Sub Main()
        Dim myform As Form = New FrmColorForm()
        Application.Run(myform)
   End Sub " Main
End Class

Public Class FrmColorForm
   Inherits System.Windows.Forms.Form
   " input text boxes
   Friend WithEvents txtColorName As TextBox
   Friend WithEvents txtGreenBox As TextBox
   Friend WithEvents txtRedBox As TextBox
   Friend WithEvents txtAlphaBox As TextBox
   Friend WithEvents txtBlueBox As TextBox
   " set color command buttons
   Friend WithEvents cmdColorName As Button
   Friend WithEvents cmdColorValue As Button
   " color labels
   Friend WithEvents lblBlue As Label
   Friend WithEvents lblGreen As Label
   Friend WithEvents lblRed As Label
   Friend WithEvents lblAlpha As Label
   " group boxes
   Friend WithEvents nameBox As GroupBox
   Friend WithEvents colorValueGroup As GroupBox
#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
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.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.nameBox = New System.Windows.Forms.GroupBox()
      Me.cmdColorName = New System.Windows.Forms.Button()
      Me.txtColorName = New System.Windows.Forms.TextBox()
      Me.colorValueGroup = New System.Windows.Forms.GroupBox()
      Me.lblBlue = New System.Windows.Forms.Label()
      Me.lblGreen = New System.Windows.Forms.Label()
      Me.lblRed = New System.Windows.Forms.Label()
      Me.lblAlpha = New System.Windows.Forms.Label()
      Me.txtBlueBox = New System.Windows.Forms.TextBox()
      Me.txtGreenBox = New System.Windows.Forms.TextBox()
      Me.txtRedBox = New System.Windows.Forms.TextBox()
      Me.txtAlphaBox = New System.Windows.Forms.TextBox()
      Me.cmdColorValue = New System.Windows.Forms.Button()
      Me.nameBox.SuspendLayout()
      Me.colorValueGroup.SuspendLayout()
      Me.SuspendLayout()
      "
      "nameBox
      "
      Me.nameBox.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdColorName, Me.txtColorName})
      Me.nameBox.Location = New System.Drawing.Point(0, 184)
      Me.nameBox.Name = "nameBox"
      Me.nameBox.Size = New System.Drawing.Size(304, 64)
      Me.nameBox.TabIndex = 0
      Me.nameBox.TabStop = False
      Me.nameBox.Text = "Set Back Color Name"
      "
      "cmdColorName
      "
      Me.cmdColorName.Location = New System.Drawing.Point(160, 24)
      Me.cmdColorName.Name = "cmdColorName"
      Me.cmdColorName.Size = New System.Drawing.Size(112, 24)
      Me.cmdColorName.TabIndex = 1
      Me.cmdColorName.Text = "Set Color Name"
      "
      "txtColorName
      "
      Me.txtColorName.Location = New System.Drawing.Point(16, 24)
      Me.txtColorName.Name = "txtColorName"
      Me.txtColorName.Size = New System.Drawing.Size(128, 20)
      Me.txtColorName.TabIndex = 0
      Me.txtColorName.Text = "Wheat"
      "
      "colorValueGroup
      "
      Me.colorValueGroup.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblBlue, Me.lblGreen, Me.lblRed, Me.lblAlpha, Me.txtBlueBox, Me.txtGreenBox, Me.txtRedBox, Me.txtAlphaBox, Me.cmdColorValue})
      Me.colorValueGroup.Location = New System.Drawing.Point(0, 248)
      Me.colorValueGroup.Name = "colorValueGroup"
      Me.colorValueGroup.Size = New System.Drawing.Size(304, 56)
      Me.colorValueGroup.TabIndex = 1
      Me.colorValueGroup.TabStop = False
      Me.colorValueGroup.Text = "Set Front Color Value"
      "
      "lblBlue
      "
      Me.lblBlue.Location = New System.Drawing.Point(128, 16)
      Me.lblBlue.Name = "lblBlue"
      Me.lblBlue.Size = New System.Drawing.Size(40, 16)
      Me.lblBlue.TabIndex = 7
      Me.lblBlue.Text = "Blue"
      "
      "lblGreen
      "
      Me.lblGreen.Location = New System.Drawing.Point(88, 16)
      Me.lblGreen.Name = "lblGreen"
      Me.lblGreen.Size = New System.Drawing.Size(40, 16)
      Me.lblGreen.TabIndex = 6
      Me.lblGreen.Text = "Green"
      "
      "lblRed
      "
      Me.lblRed.Location = New System.Drawing.Point(56, 16)
      Me.lblRed.Name = "lblRed"
      Me.lblRed.Size = New System.Drawing.Size(32, 16)
      Me.lblRed.TabIndex = 5
      Me.lblRed.Text = "Red"
      "
      "lblAlpha
      "
      Me.lblAlpha.Location = New System.Drawing.Point(8, 16)
      Me.lblAlpha.Name = "lblAlpha"
      Me.lblAlpha.Size = New System.Drawing.Size(40, 16)
      Me.lblAlpha.TabIndex = 4
      Me.lblAlpha.Text = "Alpha"
      "
      "txtBlueBox
      "
      Me.txtBlueBox.Location = New System.Drawing.Point(128, 32)
      Me.txtBlueBox.Name = "txtBlueBox"
      Me.txtBlueBox.Size = New System.Drawing.Size(32, 20)
      Me.txtBlueBox.TabIndex = 3
      Me.txtBlueBox.Text = "255"
      "
      "txtGreenBox
      "
      Me.txtGreenBox.Location = New System.Drawing.Point(88, 32)
      Me.txtGreenBox.Name = "txtGreenBox"
      Me.txtGreenBox.Size = New System.Drawing.Size(32, 20)
      Me.txtGreenBox.TabIndex = 2
      Me.txtGreenBox.Text = "0"
      "
      "txtRedBox
      "
      Me.txtRedBox.Location = New System.Drawing.Point(48, 32)
      Me.txtRedBox.Name = "txtRedBox"
      Me.txtRedBox.Size = New System.Drawing.Size(32, 20)
      Me.txtRedBox.TabIndex = 1
      Me.txtRedBox.Text = "0"
      "
      "txtAlphaBox
      "
      Me.txtAlphaBox.Location = New System.Drawing.Point(8, 32)
      Me.txtAlphaBox.Name = "txtAlphaBox"
      Me.txtAlphaBox.Size = New System.Drawing.Size(32, 20)
      Me.txtAlphaBox.TabIndex = 0
      Me.txtAlphaBox.Text = "100"
      "
      "cmdColorValue
      "
      Me.cmdColorValue.Location = New System.Drawing.Point(168, 32)
      Me.cmdColorValue.Name = "cmdColorValue"
      Me.cmdColorValue.Size = New System.Drawing.Size(112, 24)
      Me.cmdColorValue.TabIndex = 3
      Me.cmdColorValue.Text = "Set Color Value"
      "
      "FrmColorForm
      "
      Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
      Me.ClientSize = New System.Drawing.Size(304, 309)
      Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.colorValueGroup, Me.nameBox})
      Me.Name = "FrmColorForm"
      Me.Text = "Using Colors"
      Me.nameBox.ResumeLayout(False)
      Me.colorValueGroup.ResumeLayout(False)
      Me.ResumeLayout(False)
   End Sub
#End Region
   " color for back rectangle
   Private mBehindColor As Color = Color.Wheat
   " color for front rectangle
   Private mFrontColor As Color = Color.FromArgb(100, 0, 0, 255)
   " overrides Form OnPaint method
   Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
      Dim graphicsObject As Graphics = e.Graphics " get graphics
      Dim textBrush As SolidBrush = New SolidBrush(Color.Black) 
      Dim brush As SolidBrush = New SolidBrush(Color.White) 
      graphicsObject.FillRectangle(brush, 4, 4, 275, 180)
      graphicsObject.DrawString(mBehindColor.Name, Me.Font, _
         textBrush, 40, 5)
      brush.Color = mBehindColor
      graphicsObject.FillRectangle(brush, 45, 20, 150, 120)
      graphicsObject.DrawString("Alpha: " & mFrontColor.A & _
         " Red: " & mFrontColor.R & " Green: " & mFrontColor.G _
         & " Blue: " & mFrontColor.B, Me.Font, textBrush, _
         55, 165)
      brush.Color = mFrontColor
      graphicsObject.FillRectangle(brush, 65, 35, 170, 130)
   End Sub
   Private Sub cmdColorValue_Click(ByVal sender As _
      System.Object, ByVal e As System.EventArgs) _
      Handles cmdColorValue.Click
      mFrontColor = Color.FromArgb(txtAlphaBox.Text, _
         txtRedBox.Text, txtGreenBox.Text, txtBlueBox.Text)
      Invalidate()
   End Sub
   Private Sub cmdColorName_Click(ByVal sender As _
      System.Object, ByVal e As System.EventArgs) _
      Handles cmdColorName.Click
      mBehindColor = Color.FromName(txtColorName.Text)
      Invalidate()
   End Sub
End Class