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

Endless Looping with Font.Colors in Visual Basic 2010

P: 10
I'm trying to make is so that a Name located in lblName...will be continually changing the color of the Font Letter in the same order when I click the Form1

So click Form1

The Name will be Red, Click again Name will be in White, Click again Name will be Blue , click again Name will be Purple, click again the Name will be Orange, and the process startes all over again..Color is the same...

What am i doing wrong here...? should I have have
Expand|Select|Wrap|Line Numbers
  1.  For Num > 4 Then Num = 0 
  2.         Me.lblName = MyColors(Num)
Here is the code...hopefully somebody can help

I feel like there's something else missing like
Font.Color or something...


Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim MyColors(4) As Color 'Global
  3.     Dim Num As Integer 'Global, automatically initialized to 0
  4.  
  5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As  _
  6.             System.EventArgs) Handles MyBase.Load
  7.         MyColors(0) = Color.Red
  8.         MyColors(1) = Color.White
  9.         MyColors(2) = Color.Blue
  10.         MyColors(3) = Color.Purple
  11.         MyColors(4)= Color.Orange
  12.     End Sub 'Form1_Load
  13.  
  14.     Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As  _
  15.             System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
  16.         Num =( Num + 1) Mod 5
  17.          IF Num > 4 Then Num = 0 
  18.         Me.lblName = MyColors(Num)
  19.  
  20.     End Sub 'Form1_MouseClick
  21. End Class
Apr 9 '12 #1

✓ answered by Monomachus

Try this.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As  _
  2.             System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
  3.         Num = (Num + 1) Mod 5
  4.         If Num > 4 Then Num = 0
  5.         Me.lblName.ForeColor = MyColors(Num)
  6.  
  7.     End Sub 'Form1_MouseClick

Share this Question
Share on Google+
1 Reply


Monomachus
Expert 100+
P: 127
Try this.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As  _
  2.             System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
  3.         Num = (Num + 1) Mod 5
  4.         If Num > 4 Then Num = 0
  5.         Me.lblName.ForeColor = MyColors(Num)
  6.  
  7.     End Sub 'Form1_MouseClick
Apr 9 '12 #2

Post your reply

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