Visual basic random colors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • terry guthrie
    New Member
    • Sep 2007
    • 4

    #1

    Visual basic random colors

    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.
    [code=vb]
    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
    Button1.BackCol or = Color.Aqua
    End Sub[/code]
    can anyone help me
    Last edited by pbmods; Sep 1 '07, 11:23 PM. Reason: Added CODE tags.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    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.

    Comment

    • terry guthrie
      New Member
      • Sep 2007
      • 4

      #3
      Thank you, this was my first time to your web sight and got a little confused, so i thank you for your patience
      Originally posted by pbmods
      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.

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #4
        Originally posted by terry guthrie
        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.
        [code=vb]
        Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
        Button1.BackCol or = Color.Aqua
        End Sub[/code]
        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

        Comment

        • sgrec7
          New Member
          • Aug 2007
          • 58

          #5
          hey terry, there is an easier way...

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

          Code:
          private sub button1_click(BlaBlaBla) handles BlaBlaBLa
          
          dim aa as integer
          
          aa = int (rnd () * 5) + 1
          
          if aa = 1 then
          button1.backcolor = blue (or what ever the code is for blue)
          
          elseif aa = 2 then
          button1.backcolor = green
          
          elseif aa = 3 then
          button1.backcolor = red
          
          elseif aa = 4 then
          button1.backcolor = yellow
          
          elseif aa = 5 then
          button1.backcolor = orange
          
          endif
          i hope this works, if it doesn't then PM me and i'll figure it out

          ok then cya

          sgrec7

          Comment

          Working...