473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Trying to create a colour reference form

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?

--
|
+-- Thief_
|
Nov 21 '05 #1
4 1429
Thief_ wrote:
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
Nov 21 '05 #2
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

--
|
+-- Thief_
|

"Chris" <no@spam.com> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...
Thief_ wrote:
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

Nov 21 '05 #3
"Thief_" <th****@hotmail.com> schrieb
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

Nov 21 '05 #4
Hi,

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

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

Ken
------------------
"Thief_" <th****@hotmail.com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
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?

--
|
+-- Thief_
|

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Craig | last post by:
I have a page that has a few columns and totals. I've been asked to amke sure that not only is the totals boxes readonly, they must not accept focus from the cursor. However, setting the bo to...
5
by: Steve Amey | last post by:
Hi all I have an ARGB value for a Colour (Eg. -65536. The value was retrieved by using the Color.ToArgb method), is there any way that I can create a System.Drawing.Image or a...
6
by: Lapchien | last post by:
One of my users has asked that a form change it's colour if a particular yes/no box is ticked - possibly made a bit more tricky because the form is tabular..? Thanks, Lap
3
by: MS | last post by:
I need to determine CMYK values from bitmaps. Is there a way in VB or Access to do this? The reason is that I need to determin the relative CMYK values. Example: A square with the bottom half...
3
by: Tim Marshall | last post by:
I would swear that when I developed in A97, I could change the back colour of a form. However, in Windows XP, on both A97 and A2003, there no longer is a property showing in the format tab for...
26
by: johkar | last post by:
I need to cancel the link and execute a function onclick of all the links within the span tag which has a class of "container" assigned. There will be only one span tag with this class applied. ...
6
by: windandwaves | last post by:
Hi Folk Some of my clients asked me to create "fancy emails" for them (aka html formatted emails). I know how to make a nice html document, but I had trouble creating a simple way to provide...
0
by: Kristian Frost | last post by:
Hi, I'm just getting started with VB.Net, and I'm having trouble getting the routing around of some of the data straight in my mind, which has led me to the following problem. Basically, I'm...
3
by: bettyboo | last post by:
Hi I'm new to the forum and also a VERY new user of Access to develop databases. I'm building a DB for a driving instructor acquaintance, and he wants a button on the pupil data entry form which...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.