|
-
Dec 23rd, 2003, 12:56 AM
#1
Thread Starter
Frenzied Member
screwing around with backcolor [RESOLVED]
I was just fooling around and wanted to make a button change the backcolor of a form and have a label show the color name. I figure the best way to do this is to have an index # of all colors in the system.drawing.color property and make a loop to change that everytime the click event is fired. then convert the index # to a string and change the text of the label to that color name. what is the best approach here?
Last edited by Andy; Feb 11th, 2004 at 09:56 PM.
-
Dec 23rd, 2003, 04:54 AM
#2
made this for you , hope it helps
VB Code:
Dim x As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As Type = GetType(Color)
Dim strColors As String() = t.Attributes.GetNames(GetType(System.Drawing.KnownColor))
ListBox1.Items.AddRange(strColors)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If x < ListBox1.Items.Count Then
Me.BackColor = Color.FromName(ListBox1.Items(x))
x += 1
End If
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Dec 23rd, 2003, 05:45 AM
#3
Thread Starter
Frenzied Member
hey sys, that's great!! Thanks. not exactly what I was after but definetly cool!
One problem, and I'm sure this is because of an RGB thing or something, but some of the colors listed in the box either show as white or dark, dark blue and not as the color listed (ie Tomato shows white) could that be that my monitor doesn't display that color? Or could it be the fact (and I'll experiment) that I'm using my Studio over a remote desktop connection?
AND could you explain how you came up with that code? I'd like to know your step-by-step process of coming up with answers. I don't mind so much getting answers to problems but I'm one who likes to be taught HOW to GET the answers and I'm sure teachers appreciate that.
-
Dec 23rd, 2003, 06:01 AM
#4
Thread Starter
Frenzied Member
ah, I see what it's doing now. no matter WHAT color is selected, button2 simply goes through a series of colors. it doesn't show the color selected at all (unless you cycle through and up to it). When the cycle gets to a transparent color, the app crashes.
What I'd really like to do is have a label display the color of the background that button1 cycles through (and skips transparent). but here's the catch, I was only wanting the colors supported by system.drawing.color namespace.
any ideas on THIS one?
-
Dec 23rd, 2003, 08:19 AM
#5
Sleep mode
This ?
VB Code:
Me.Label1.BackColor = Color.FromName(ListBox1.Text)
-
Dec 23rd, 2003, 08:22 AM
#6
Sleep mode
dynamic_sysop , do you know how to iterate through KnownColor enum using foreach loop . I did it a month ago but forgot how exactly .
-
Dec 23rd, 2003, 02:37 PM
#7
sorry , been busy all day with xmas aproaching fast
VB Code:
Dim strColor As String
For Each strColor In GetType(Drawing.KnownColor).Attributes().GetNames(GetType(Drawing.KnownColor))
Console.WriteLine(strColor)
Next
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Dec 23rd, 2003, 02:50 PM
#8
Sleep mode
Merry Christmas.
Actually , it's not that what I mean . It's more shorter than this and doesn't use attributes I believe . It's ok
-
Dec 23rd, 2003, 05:19 PM
#9
have you tried type.getfields? along with reflection.Fieldifo. eg:
VB Code:
Dim strColors As Reflection.FieldInfo() = GetType(KnownColor).GetFields
Dim strCol As Reflection.FieldInfo
For Each strCol In strColors
Console.WriteLine(strCol.Name)
Next
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Dec 23rd, 2003, 05:38 PM
#10
Sleep mode
That's cool . This is what I'm talking about .......
Code:
KnownColor kn;
for ( kn=KnownColor.AliceBlue ;kn<=KnownColor.YellowGreen;kn++)
{
this.listBox1.Items.Add(kn.ToString());
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|