i want to write something on label control in run time
i draw ten label controls on the form
and i have placed a button on the form
i want to write text on each label at a time
when i press button first time then text should be displayed on label1 and when i press button second time then text should be displayed on the second label and so on
when i use this code then it displays text on the all labels
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "a"
Label2.Text = "g"
End Sub
now how can i change text of label each time when i press the button
thnaks
Loading
Vijaya KadiyalaPosted Apr 9, 2008, 1:10 PM
Hi,
these lables creation dynamic or static? if it static then you just need to refer to the lable name. If it dynamic you may want to use Control Array.
Thanks -- Vj
http://dotnetvj.blogspot.com
AlanPosted Apr 8, 2008, 5:00 AM
You need to declare a form level variable to keep track of how many times the button has been pressed and then to reset it after it's been pressed 10 times.
Private ButtonPushes As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ButtonPushes = ButtonPushes + 1
If ButtonPushes > 10 Then ButtonPushes = 1
Select Case ButtonPushes
Case 1
Label1.Text = "a"
Case 2
Label2.Text = "g"
' Other cases
End Select
End Sub