Trying to create a colour reference form

T

Thief_

I'm trying to create many squares on a form and for every new square, change
the background colour to the next colour. I'm trying to create a colour
palette showing all available colours and their colour name.

My problem is that I can not figger out how to create a new panel at
specific intervals across and down the form. Here's the code I have so far:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim xNum As Byte = 4
Dim yNum As Byte = 2
Dim xLoc As Integer = 10
Dim yLoc As Integer = 10
Dim Spacer As Integer = 10
Dim ColourIndex As Object
Dim PanelHeight As Integer = 50

For y As Byte = 1 To yNum
For x As Byte = 1 To xNum
Dim NewPanelObj As New Panel
With NewPanelObj
.Left = xLoc
.Top = yLoc
.BackColor = CType(ColourIndex, Color)
xLoc += .Width + Spacer
End With
Next
yLoc += PanelHeight + Spacer
Next
End Sub

Can someone help me?
 
C

Chris

Thief_ said:
I'm trying to create many squares on a form and for every new square, change
the background colour to the next colour. I'm trying to create a colour
palette showing all available colours and their colour name.

My problem is that I can not figger out how to create a new panel at
specific intervals across and down the form. Here's the code I have so far:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim xNum As Byte = 4
Dim yNum As Byte = 2
Dim xLoc As Integer = 10
Dim yLoc As Integer = 10
Dim Spacer As Integer = 10
Dim ColourIndex As Object
Dim PanelHeight As Integer = 50

For y As Byte = 1 To yNum
For x As Byte = 1 To xNum
Dim NewPanelObj As New Panel
With NewPanelObj
.Left = xLoc
.Top = yLoc
.BackColor = CType(ColourIndex, Color)
xLoc += .Width + Spacer
End With
Next
yLoc += PanelHeight + Spacer
Next
End Sub

Can someone help me?

Well you never add the panel to the form. Add a panel to the form
through the designer. Then open up the Windows Generated Code and see
how they add the control to the form.

Another idea would be to override the onpaint method of the form. Then
do something like:

e.Graphics.FillRectangle(Brushes.Black,......)

Good Luck
Chris
 
T

Thief_

Thanks Chris,

I now have an automated procedure to place (RED) coloured panels over my
form. My last question is, how do I alternate the colour of each panel so
that all NET colours are displayed, along with their NET name?

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim xNum As Byte = 10
Dim yNum As Byte = 10
Dim xLoc As Integer = 10
Dim yLoc As Integer = 10
Dim Spacer As Integer = 10
Dim ColourIndex As Object
Dim PanelHeight As Integer = 50

For y As Byte = 1 To yNum
For x As Byte = 1 To xNum
Dim NewPanel As New System.Windows.Forms.Panel
Me.Controls.Add(NewPanel)
With NewPanel
.BorderStyle = BorderStyle.Fixed3D
.Width = 50
.Height = 50
.Left = xLoc
.Top = yLoc
.BackColor = Color.Red ' CType(ColourIndex, Color)
xLoc += .Width + Spacer
ColourIndex += 1
End With
Next
xLoc = 10
yLoc += PanelHeight + Spacer
Next
End Sub
 
A

Armin Zingler

Thief_ said:
I now have an automated procedure to place (RED) coloured panels
over my form. My last question is, how do I alternate the colour of
each panel so that all NET colours are displayed, along with their
NET name?


Getting all names into an Array of Strings:

Dim T As Type
Dim PInfos As Reflection.PropertyInfo()
Dim al As New ArrayList
Dim Names As String()

T = GetType(Color)

PInfos = T.GetProperties( _
Reflection.BindingFlags.Static Or Reflection.BindingFlags.Public _
)

For Each PInfo As Reflection.PropertyInfo In PInfos
If PInfo.PropertyType Is T Then
al.Add(PInfo.Name)
End If
Next

Names = DirectCast(al.ToArray(GetType(String)), String())


Use Color.FromName to get a color from the name.



If you want to use the System.Drawing.KnownColor Enum, this is how you can
get the names/values:

Dim KnownColors As KnownColor()

Names = [Enum].GetNames(GetType(KnownColor))
KnownColors = DirectCast([Enum].GetValues(GetType(KnownColor)),
KnownColor())



Armin
 
K

Ken Tucker [MVP]

Hi,

This doesnt get the name for you but this example might help.

http://www.bobpowell.net/giftransparency.htm

Ken
------------------
I'm trying to create many squares on a form and for every new square, change
the background colour to the next colour. I'm trying to create a colour
palette showing all available colours and their colour name.

My problem is that I can not figger out how to create a new panel at
specific intervals across and down the form. Here's the code I have so far:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim xNum As Byte = 4
Dim yNum As Byte = 2
Dim xLoc As Integer = 10
Dim yLoc As Integer = 10
Dim Spacer As Integer = 10
Dim ColourIndex As Object
Dim PanelHeight As Integer = 50

For y As Byte = 1 To yNum
For x As Byte = 1 To xNum
Dim NewPanelObj As New Panel
With NewPanelObj
.Left = xLoc
.Top = yLoc
.BackColor = CType(ColourIndex, Color)
xLoc += .Width + Spacer
End With
Next
yLoc += PanelHeight + Spacer
Next
End Sub

Can someone help me?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top