Track Form background Color : Color « 2D « VB.Net






Track Form background Color

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.ComponentModel.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.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TrackBar2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TrackBar3, System.ComponentModel.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.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TrackBar2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TrackBar3, System.ComponentModel.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

           
       








Related examples in the same category

1.Get all Known color and calcuate its Brightness and SaturationGet all Known color and calcuate its Brightness and Saturation
2.Using different colors in Visual BasicUsing different colors in Visual Basic
3.Color Dialog: Changing the background and text colors of a formColor Dialog: Changing the background and text colors of a form
4.Construct Color from R G B ValueConstruct Color from R G B Value
5.Use color dialog to set form backgroundUse color dialog to set form background