By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Visual basic random colors

P: 4
Hi I am taking a class that involvs visual basic, I have created buttons that when clicked come up in a color, i now need to have them come up in Random colors.
here is the formula i have so far.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Button1.BackColor = Color.Aqua
  3.     End Sub
can anyone help me
Sep 1 '07 #1
Share this Question
Share on Google+
4 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Terry. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

I'm going to go ahead and move this thread to the Visual Basic forum, where our resident Experts will be better able to help you out.
Sep 1 '07 #2

P: 4
Thank you, this was my first time to your web sight and got a little confused, so i thank you for your patience
Heya, Terry. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

I'm going to go ahead and move this thread to the Visual Basic forum, where our resident Experts will be better able to help you out.
Sep 1 '07 #3

SammyB
Expert 100+
P: 807
Hi I am taking a class that involvs visual basic, I have created buttons that when clicked come up in a color, i now need to have them come up in Random colors.
here is the formula i have so far.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Button1.BackColor = Color.Aqua
  3. End Sub
can anyone help me
See this thread for an intro to random numbers. Just look at my posts that deal with .NET. You've found and used the Color class; now, you just need to create a new Color object and set the Red, Green, and Blue components to a random number. HTH --Sam
Sep 1 '07 #4

sgrec7
P: 59
hey terry, there is an easier way...

say you want 5 different colours to randomly be the back colour..

Expand|Select|Wrap|Line Numbers
  1.  
  2. private sub button1_click(BlaBlaBla) handles BlaBlaBLa
  3.  
  4. dim aa as integer
  5.  
  6. aa = int (rnd () * 5) + 1
  7.  
  8. if aa = 1 then
  9. button1.backcolor = blue (or what ever the code is for blue)
  10.  
  11. elseif aa = 2 then
  12. button1.backcolor = green
  13.  
  14. elseif aa = 3 then
  15. button1.backcolor = red
  16.  
  17. elseif aa = 4 then
  18. button1.backcolor = yellow
  19.  
  20. elseif aa = 5 then
  21. button1.backcolor = orange
  22.  
  23. endif
  24.  
  25.  
i hope this works, if it doesn't then PM me and i'll figure it out

ok then cya

sgrec7
Sep 2 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.