Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Color Picker
Author:
Michel Renaud
E-mail:
Click to e-mail author
Submitted:
4/23/2006
Version:
VB.NET 2003
Compatibility:
VB.NET 2003, VB 2005
Category:
Forms
Views:
18668
Select colors in combobox and set the formBackground color. I added some more features.
Declarations:
Imports System.io
Code:
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 ListBox1 As System.Windows.Forms.ListBox Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents Button3 As System.Windows.Forms.Button Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Button4 As System.Windows.Forms.Button Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox Friend WithEvents VScrollBar2 As System.Windows.Forms.VScrollBar Friend WithEvents VScrollBar3 As System.Windows.Forms.VScrollBar Friend WithEvents VScrollBar4 As System.Windows.Forms.VScrollBar Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents VScrollBar5 As System.Windows.Forms.VScrollBar Friend WithEvents Label6 As System.Windows.Forms.Label
Private Sub InitializeComponent() Me.ListBox1 = New System.Windows.Forms.ListBox Me.GroupBox1 = New System.Windows.Forms.GroupBox Me.Button4 = New System.Windows.Forms.Button Me.Label1 = New System.Windows.Forms.Label Me.Button3 = New System.Windows.Forms.Button Me.Button1 = New System.Windows.Forms.Button Me.Button2 = New System.Windows.Forms.Button Me.GroupBox2 = New System.Windows.Forms.GroupBox Me.Label6 = New System.Windows.Forms.Label Me.VScrollBar5 = New System.Windows.Forms.VScrollBar Me.Label5 = New System.Windows.Forms.Label Me.Label4 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.VScrollBar4 = New System.Windows.Forms.VScrollBar Me.VScrollBar3 = New System.Windows.Forms.VScrollBar Me.VScrollBar2 = New System.Windows.Forms.VScrollBar Me.GroupBox1.SuspendLayout() Me.GroupBox2.SuspendLayout() Me.SuspendLayout() ' 'ListBox1 ' Me.ListBox1.Location = New System.Drawing.Point(0, 48) Me.ListBox1.Name = "ListBox1" Me.ListBox1.Size = New System.Drawing.Size(312, 212) Me.ListBox1.TabIndex = 0 ' 'GroupBox1 ' Me.GroupBox1.Controls.Add(Me.Button4) Me.GroupBox1.Controls.Add(Me.Label1) Me.GroupBox1.Controls.Add(Me.Button3) Me.GroupBox1.Controls.Add(Me.Button1) Me.GroupBox1.Controls.Add(Me.Button2) Me.GroupBox1.Location = New System.Drawing.Point(0, 0) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(536, 48) Me.GroupBox1.TabIndex = 1 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Tools" ' 'Button4 ' Me.Button4.Location = New System.Drawing.Point(272, 16) Me.Button4.Name = "Button4" Me.Button4.Size = New System.Drawing.Size(80, 24) Me.Button4.TabIndex = 5 Me.Button4.Text = "Color palette" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(96, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(112, 24) Me.Label1.TabIndex = 4 ' 'Button3 ' Me.Button3.Location = New System.Drawing.Point(360, 16) Me.Button3.Name = "Button3" Me.Button3.Size = New System.Drawing.Size(72, 24) Me.Button3.TabIndex = 3 Me.Button3.Text = "GrayScale" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(8, 16) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(80, 24) Me.Button1.TabIndex = 0 Me.Button1.Text = "Sys Colors" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(448, 16) Me.Button2.Name = "Button2" Me.Button2.TabIndex = 2 Me.Button2.Text = "Rnd Color" ' 'GroupBox2 ' Me.GroupBox2.Controls.Add(Me.Label6) Me.GroupBox2.Controls.Add(Me.VScrollBar5) Me.GroupBox2.Controls.Add(Me.Label5) Me.GroupBox2.Controls.Add(Me.Label4) Me.GroupBox2.Controls.Add(Me.Label3) Me.GroupBox2.Controls.Add(Me.Label2) Me.GroupBox2.Controls.Add(Me.VScrollBar4) Me.GroupBox2.Controls.Add(Me.VScrollBar3) Me.GroupBox2.Controls.Add(Me.VScrollBar2) Me.GroupBox2.Location = New System.Drawing.Point(320, 56) Me.GroupBox2.Name = "GroupBox2" Me.GroupBox2.Size = New System.Drawing.Size(304, 200) Me.GroupBox2.TabIndex = 2 Me.GroupBox2.TabStop = False Me.GroupBox2.Text = "RGB Colors" ' 'Label6 ' Me.Label6.Location = New System.Drawing.Point(144, 160) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(96, 32) Me.Label6.TabIndex = 9 ' 'VScrollBar5 ' Me.VScrollBar5.Location = New System.Drawing.Point(248, 24) Me.VScrollBar5.Maximum = 130 Me.VScrollBar5.Minimum = 1 Me.VScrollBar5.Name = "VScrollBar5" Me.VScrollBar5.Size = New System.Drawing.Size(16, 168) Me.VScrollBar5.TabIndex = 8 Me.VScrollBar5.Value = 1 ' 'Label5 ' Me.Label5.Location = New System.Drawing.Point(152, 120) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(88, 32) Me.Label5.TabIndex = 7 ' 'Label4 ' Me.Label4.Location = New System.Drawing.Point(152, 88) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(88, 24) Me.Label4.TabIndex = 6 ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(152, 56) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(88, 24) Me.Label3.TabIndex = 5 ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(152, 24) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(88, 24) Me.Label2.TabIndex = 4 ' 'VScrollBar4 ' Me.VScrollBar4.Location = New System.Drawing.Point(120, 16) Me.VScrollBar4.Maximum = 250 Me.VScrollBar4.Name = "VScrollBar4" Me.VScrollBar4.Size = New System.Drawing.Size(16, 176) Me.VScrollBar4.TabIndex = 3 ' 'VScrollBar3 ' Me.VScrollBar3.Location = New System.Drawing.Point(72, 16) Me.VScrollBar3.Maximum = 250 Me.VScrollBar3.Minimum = 1 Me.VScrollBar3.Name = "VScrollBar3" Me.VScrollBar3.Size = New System.Drawing.Size(16, 176) Me.VScrollBar3.TabIndex = 2 Me.VScrollBar3.Value = 1 ' 'VScrollBar2 ' Me.VScrollBar2.Location = New System.Drawing.Point(24, 16) Me.VScrollBar2.Maximum = 250 Me.VScrollBar2.Minimum = 1 Me.VScrollBar2.Name = "VScrollBar2" Me.VScrollBar2.Size = New System.Drawing.Size(16, 176) Me.VScrollBar2.TabIndex = 1 Me.VScrollBar2.Value = 1 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(672, 266) Me.Controls.Add(Me.GroupBox2) Me.Controls.Add(Me.GroupBox1) Me.Controls.Add(Me.ListBox1) Me.Name = "Form1" Me.Text = "Form1" Me.GroupBox1.ResumeLayout(False) Me.GroupBox2.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim color As Color Dim i As Integer For Each color In System.ComponentModel.TypeDescriptor.GetConverter(GetType(Color)).GetStandardValues i += 1 ListBox1.Items.Add(color.ToKnownColor) Next Label1.Text = "Color Count: " & i End Sub Function GetRandomColor() As Color Dim rand As New Random Return Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, _ 256)) End Function Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.BackColor = GetRandomColor() End Sub Function GetGreyScale(ByVal col As Color) As Color Dim greyValue As Integer = CType(col.R * 0.3 + col.G * 0.59 + col.B * 0.11, _ Integer) Return Color.FromArgb(greyValue, greyValue, greyValue) End Function Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.BackColor = GetGreyScale(Color.ForestGreen) End Sub Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click Me.BackColor = Color.FromKnownColor(ListBox1.SelectedItem) End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim Palette As New ColorDialog With Palette .ShowDialog() Me.BackColor = .Color End With End Sub 'set values for the scroll bars Dim R, G, B As Integer Private Sub VScrollBar2_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar2.Scroll R = VScrollBar2.Value Me.BackColor = Color.FromArgb(R, G, B) Label3.Text = "Red " & VScrollBar2.Value End Sub Private Sub VScrollBar3_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar3.Scroll G = VScrollBar3.Value Me.BackColor = System.Drawing.Color.FromArgb(R, G, B) Label4.Text = "Green " & VScrollBar3.Value End Sub Private Sub VScrollBar4_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar4.Scroll B = VScrollBar4.Value Me.BackColor = Color.FromArgb(R, G, B) Label5.Text = "Blue " & VScrollBar4.Value End Sub Private Sub VScrollBar5_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar5.Scroll Me.Opacity = VScrollBar5.Value / 100 Label6.Text = "Opacity " & Me.Opacity.ToString End Sub End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement