Loopin trough colors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nedim

    #1

    Loopin trough colors

    first let me say sorry if this is in the wrong place, i'm pretty new to
    programming and to be honest i am a bit intimidated by these forums.

    now that i've got that out of the way, i was bored and decided to make a
    small text application in Visual Basic 2005,

    i have one list box, one label and ten buttons.

    the list box has 8 colors listed, and when one of them is selected and the
    OK button clicked the text in the label changes color, the same with other 8
    buttons, but instead of selecting a color from the list the other buttons
    change the color of the text directly.

    the problem is the tenth button, it's supposed to loop trough all 8 colors,
    but it skips directly to the last one (purple) and stays there, the code i
    used is this:



    Dim myColor() As Color = {Color.Blue, Color.Red, Color.Green,
    Color.Yellow, Color.Black, Color.White, Color.Orange, Color.Purple}

    Dim textcollor As Color
    For Each textcollor In myColor
    Label1.ForeColo r = (textcollor)
    Next


  • Cowboy \(Gregory A. Beamer\)

    #2
    Re: Loopin trough colors

    You want to see it scroll through the colors? If so, you need to pause and
    paint after each change. Otherwise, it is changing, but not painting until
    the entire loop is done. Am I understanding your desire correctly?

    --
    Gregory A. Beamer

    *************** *************** *************** ****
    Think Outside the Box!
    *************** *************** *************** ****
    "Nedim" <Nedim@discussi ons.microsoft.c om> wrote in message
    news:451468DB-7AAD-4DB9-A816-7AFB6121F359@mi crosoft.com...[color=blue]
    > first let me say sorry if this is in the wrong place, i'm pretty new to
    > programming and to be honest i am a bit intimidated by these forums.
    >
    > now that i've got that out of the way, i was bored and decided to make a
    > small text application in Visual Basic 2005,
    >
    > i have one list box, one label and ten buttons.
    >
    > the list box has 8 colors listed, and when one of them is selected and the
    > OK button clicked the text in the label changes color, the same with other
    > 8
    > buttons, but instead of selecting a color from the list the other buttons
    > change the color of the text directly.
    >
    > the problem is the tenth button, it's supposed to loop trough all 8
    > colors,
    > but it skips directly to the last one (purple) and stays there, the code i
    > used is this:
    >
    >
    >
    > Dim myColor() As Color = {Color.Blue, Color.Red, Color.Green,
    > Color.Yellow, Color.Black, Color.White, Color.Orange, Color.Purple}
    >
    > Dim textcollor As Color
    > For Each textcollor In myColor
    > Label1.ForeColo r = (textcollor)
    > Next
    >
    >[/color]


    Comment

    • Nedim

      #3
      Re: Loopin trough colors

      yes, that is correct, i would like it to scroll trough all the colors i have
      set upon pressing the button.

      "Cowboy (Gregory A. Beamer)" wrote:
      [color=blue]
      > You want to see it scroll through the colors? If so, you need to pause and
      > paint after each change. Otherwise, it is changing, but not painting until
      > the entire loop is done. Am I understanding your desire correctly?
      >
      > --
      > Gregory A. Beamer
      >
      > *************** *************** *************** ****
      > Think Outside the Box!
      > *************** *************** *************** ****
      > "Nedim" <Nedim@discussi ons.microsoft.c om> wrote in message
      > news:451468DB-7AAD-4DB9-A816-7AFB6121F359@mi crosoft.com...[color=green]
      > > first let me say sorry if this is in the wrong place, i'm pretty new to
      > > programming and to be honest i am a bit intimidated by these forums.
      > >
      > > now that i've got that out of the way, i was bored and decided to make a
      > > small text application in Visual Basic 2005,
      > >
      > > i have one list box, one label and ten buttons.
      > >
      > > the list box has 8 colors listed, and when one of them is selected and the
      > > OK button clicked the text in the label changes color, the same with other
      > > 8
      > > buttons, but instead of selecting a color from the list the other buttons
      > > change the color of the text directly.
      > >
      > > the problem is the tenth button, it's supposed to loop trough all 8
      > > colors,
      > > but it skips directly to the last one (purple) and stays there, the code i
      > > used is this:
      > >
      > >
      > >
      > > Dim myColor() As Color = {Color.Blue, Color.Red, Color.Green,
      > > Color.Yellow, Color.Black, Color.White, Color.Orange, Color.Purple}
      > >
      > > Dim textcollor As Color
      > > For Each textcollor In myColor
      > > Label1.ForeColo r = (textcollor)
      > > Next
      > >
      > >[/color]
      >
      >
      >[/color]

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Loopin trough colors

        Nedim,

        To do it step by step.

        If you make a same array for your labels as for your collors than you can
        do.

        for i as integer = 0 to myColor.lenght
        mylabelInArray( i).ForeColor = mycolor(i)
        next

        There are endless alternatives by the way

        I hope this helps,

        Cor

        Assuming that your textboxes are in the same sequence and are
        "Nedim" <Nedim@discussi ons.microsoft.c om> schreef in bericht
        news:1D09F8B2-7C2B-4C9A-AC27-ECE81FFE2B89@mi crosoft.com...[color=blue]
        > yes, that is correct, i would like it to scroll trough all the colors i
        > have
        > set upon pressing the button.
        >
        > "Cowboy (Gregory A. Beamer)" wrote:
        >[color=green]
        >> You want to see it scroll through the colors? If so, you need to pause
        >> and
        >> paint after each change. Otherwise, it is changing, but not painting
        >> until
        >> the entire loop is done. Am I understanding your desire correctly?
        >>
        >> --
        >> Gregory A. Beamer
        >>
        >> *************** *************** *************** ****
        >> Think Outside the Box!
        >> *************** *************** *************** ****
        >> "Nedim" <Nedim@discussi ons.microsoft.c om> wrote in message
        >> news:451468DB-7AAD-4DB9-A816-7AFB6121F359@mi crosoft.com...[color=darkred]
        >> > first let me say sorry if this is in the wrong place, i'm pretty new to
        >> > programming and to be honest i am a bit intimidated by these forums.
        >> >
        >> > now that i've got that out of the way, i was bored and decided to make
        >> > a
        >> > small text application in Visual Basic 2005,
        >> >
        >> > i have one list box, one label and ten buttons.
        >> >
        >> > the list box has 8 colors listed, and when one of them is selected and
        >> > the
        >> > OK button clicked the text in the label changes color, the same with
        >> > other
        >> > 8
        >> > buttons, but instead of selecting a color from the list the other
        >> > buttons
        >> > change the color of the text directly.
        >> >
        >> > the problem is the tenth button, it's supposed to loop trough all 8
        >> > colors,
        >> > but it skips directly to the last one (purple) and stays there, the
        >> > code i
        >> > used is this:
        >> >
        >> >
        >> >
        >> > Dim myColor() As Color = {Color.Blue, Color.Red, Color.Green,
        >> > Color.Yellow, Color.Black, Color.White, Color.Orange, Color.Purple}
        >> >
        >> > Dim textcollor As Color
        >> > For Each textcollor In myColor
        >> > Label1.ForeColo r = (textcollor)
        >> > Next
        >> >
        >> >[/color]
        >>
        >>
        >>[/color][/color]


        Comment

        • Göran Andersson

          #5
          Re: Loopin trough colors

          When you set the label color, a message is sent to the control to make
          it change it's color. Use the DoEvents method to process the message
          queue, then do nothing for a while.

          Dim textColor As Color
          For Each textColor In myColor
          Label1.ForeColo r = textColor
          DoEvents
          Thread.Sleep(50 0)
          Next


          Nedim wrote:[color=blue]
          > yes, that is correct, i would like it to scroll trough all the colors i have
          > set upon pressing the button.
          >
          > "Cowboy (Gregory A. Beamer)" wrote:
          >[color=green]
          >> You want to see it scroll through the colors? If so, you need to pause and
          >> paint after each change. Otherwise, it is changing, but not painting until
          >> the entire loop is done. Am I understanding your desire correctly?
          >>
          >> --
          >> Gregory A. Beamer
          >>
          >> *************** *************** *************** ****
          >> Think Outside the Box!
          >> *************** *************** *************** ****
          >> "Nedim" <Nedim@discussi ons.microsoft.c om> wrote in message
          >> news:451468DB-7AAD-4DB9-A816-7AFB6121F359@mi crosoft.com...[color=darkred]
          >>> first let me say sorry if this is in the wrong place, i'm pretty new to
          >>> programming and to be honest i am a bit intimidated by these forums.
          >>>
          >>> now that i've got that out of the way, i was bored and decided to make a
          >>> small text application in Visual Basic 2005,
          >>>
          >>> i have one list box, one label and ten buttons.
          >>>
          >>> the list box has 8 colors listed, and when one of them is selected and the
          >>> OK button clicked the text in the label changes color, the same with other
          >>> 8
          >>> buttons, but instead of selecting a color from the list the other buttons
          >>> change the color of the text directly.
          >>>
          >>> the problem is the tenth button, it's supposed to loop trough all 8
          >>> colors,
          >>> but it skips directly to the last one (purple) and stays there, the code i
          >>> used is this:
          >>>
          >>>
          >>>
          >>> Dim myColor() As Color = {Color.Blue, Color.Red, Color.Green,
          >>> Color.Yellow, Color.Black, Color.White, Color.Orange, Color.Purple}
          >>>
          >>> Dim textcollor As Color
          >>> For Each textcollor In myColor
          >>> Label1.ForeColo r = (textcollor)
          >>> Next
          >>>[/color][/color][/color]

          Comment

          Working...