Running text in the buttons

T

tony wong

i have 2 questions

1. click button1, button1.text run. click button2, button2.text run.

2. multithreading - 2 buttons run at the same time.


Thanks a lot.

*******************************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click, Button2.Click

Dim a As Integer
For a = 1 To 500
Button1.Text = a
Application.DoEvents()
Next

End Sub
 
A

Armin Zingler

tony wong said:
i have 2 questions

1. click button1, button1.text run. click button2, button2.text
run.

2. multithreading - 2 buttons run at the same time.


Thanks a lot.

*******************************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click, Button2.Click

Dim a As Integer
For a = 1 To 500
Button1.Text = a
Application.DoEvents()
Next

End Sub

Usually don't use DoEvents. Multithreading is IMO not a good solution in
this case, too.

I'd use a Timer (System.Windows.Forms.Timer) for this purpose. In the
Timer's Tick event, update the Button text.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top