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 Pallet
Author:
Mike Renaud
Submitted:
3/8/2007
Version:
VB.NET 2003
Compatibility:
VB.NET 2003, VB 2005
Category:
Forms
Views:
17655
Just a owner drawn color pallet with button ****suports transparent colors****
Declarations:
'none
Code:
Public Class Pallet 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() ' this sub supports form level transparent colors Initialize_Transparent_Colors() 'Add any initialization after the InitializeComponent() call 'Form1 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 Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button Me.Button2 = New System.Windows.Forms.Button Me.ComboBox1 = New System.Windows.Forms.ComboBox Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(16, 0) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(64, 24) Me.Button1.TabIndex = 0 Me.Button1.Text = "Reload" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(16, 336) Me.Button2.Name = "Button2" Me.Button2.Size = New System.Drawing.Size(88, 24) Me.Button2.TabIndex = 1 Me.Button2.Text = "Color Names" ' 'ComboBox1 ' Me.ComboBox1.Location = New System.Drawing.Point(112, 336) Me.ComboBox1.Name = "ComboBox1" Me.ComboBox1.Size = New System.Drawing.Size(224, 21) Me.ComboBox1.TabIndex = 2 Me.ComboBox1.Text = "Select colors by names" ' 'Pallet ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(344, 374) Me.Controls.Add(Me.ComboBox1) Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Button1) Me.Name = "Pallet" Me.Text = "Pallet" Me.ResumeLayout(False) End Sub #End Region Dim bnt As New Button Public TheColor As Color = bnt.BackColor Dim A As New Random(1000) Dim R As New Random(50) Dim G As New Random(750) Dim B As New Random(400) 'Must use in the Form Designer Private Sub Initialize_Transparent_Colors() Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True) Me.SetStyle(ControlStyles.DoubleBuffer, True) ' Me.SetStyle(ControlStyles.Opaque, True) Me.SetStyle(ControlStyles.ResizeRedraw, True) Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True) Me.SetStyle(ControlStyles.UserPaint, True) End Sub Private Sub Pallet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MyBase.CenterToScreen() Static i, j As Integer Dim c As Color Dim Red, Blue, Green, Alpha As Integer For i = 1 To 10 bnt = New Button Red = R.Next(0, 255) Blue = B.Next(0, 255) Green = G.Next(0, 255) Alpha = A.Next(0, 255) For j = 1 To 10 bnt = New Button Red = R.Next(0, 255) Blue = B.Next(0, 255) Green = G.Next(0, 255) Alpha = A.Next(0, 255) With bnt .BackColor = Color.FromArgb(Alpha, Red, Green, Blue) .Height = 25 .Width = 25 .Location = New System.Drawing.Point(CInt(i * (bnt.Width + 5)), j * CInt(bnt.Height + 5)) .Visible = True End With AddHandler bnt.Click, AddressOf bnt_click Me.Controls.Add(bnt) Next Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim crt As System.Windows.Forms.Control For Each crt In Me.Controls If crt.GetType Is GetType(Button) Then Dim Red, Blue, Green, Alpha As Integer Red = R.Next(0, 255) Blue = B.Next(0, 255) Green = G.Next(0, 255) Alpha = A.Next(0, 255) crt.BackColor = Color.FromArgb(Alpha, Red, Green, Blue) End If Next End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim typ As System.Type = GetType(System.Drawing.Color) Dim aPropInfo As System.Reflection.PropertyInfo() = typ.GetProperties() For Each pi As System.Reflection. _ PropertyInfo In aPropInfo If pi.PropertyType.Name = "Color" _ And pi.Name <> "Transparent" Then Me.ComboBox1.Items.Add(pi.Name) End If Next End Sub Friend WithEvents frm As New Form1 Private Sub bnt_click(ByVal Sender As System.Object, ByVal e As System.EventArgs) ' frm.Show() frm.BackColor = (CType(CType(Sender, Button).BackColor, Color)) frm.Show() Me.TopMost = True ' or me.BackColor = (CType(CType(Sender, Button).BackColor, Color)) End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged frm.Show() frm.BackColor = Color.FromName(Me.ComboBox1.SelectedItem) Me.TopMost = True ' or me.backcolor=Color.FromName(Me.ComboBox1.SelectedItem) End Sub Private Sub Pallet_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize Me.Validate() 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