jimtxas
asked on
VB.NET Update Labels and Progressbars on forms
I am a veteran vb6 programmer finally upgrading...
In the old days if I was in a module and needed to update a status label or progress bar, i just called it via:
frmmain.progressbar1.value = newvalue
or
frmmain.label1.caption = "NEW LABEL"
How do I do it this easily in the new world?
Tks,
J
In the old days if I was in a module and needed to update a status label or progress bar, i just called it via:
frmmain.progressbar1.value
or
frmmain.label1.caption = "NEW LABEL"
How do I do it this easily in the new world?
Tks,
J
To finish the above sample code,
* assuming Form1 has a progress bar called pb
* assuming StatusBar is called sb
* assuming StatusBar (sb) contains two panels called p1 and p2
Public Sub Whatever()
frm1.pb.Incriment() 'Increments the progress bar by 1
frm1.pb.Incriment(12) 'Incriment the progress bar by 12
frm1.pb.Value = 50 'Set the progress to 50, wherever that happens to be between pb.minimum and pb.maximum
p1.text = "New Text"
p2.text = "More new text"
End Sub
* assuming Form1 has a progress bar called pb
* assuming StatusBar is called sb
* assuming StatusBar (sb) contains two panels called p1 and p2
Public Sub Whatever()
frm1.pb.Incriment() 'Increments the progress bar by 1
frm1.pb.Incriment(12) 'Incriment the progress bar by 12
frm1.pb.Value = 50 'Set the progress to 50, wherever that happens to be between pb.minimum and pb.maximum
p1.text = "New Text"
p2.text = "More new text"
End Sub
OK, misread that, 2 corrections:
Two lines:
p1.text = "New Text"
p2.text = "More new text"
Should Read:
frm1.p1.text = "New Text"
frm1.p2.text = "More new text"
For a label:
* assuming Form1 contains lable called lbl1
frm1.lbl1.text = "New Text"
Two lines:
p1.text = "New Text"
p2.text = "More new text"
Should Read:
frm1.p1.text = "New Text"
frm1.p2.text = "More new text"
For a label:
* assuming Form1 contains lable called lbl1
frm1.lbl1.text = "New Text"
ASKER
great! i was missing the declaration of the object reference. I figured it would be something simple....
I've increased to 500, can you now tell me how to do the old fashioned form.refresh, label.refresh, etc and get the form to respond to these refreshes... seems like I saw something different somewhere than just using the refresh call... What's the DoEvents call?
I've increased to 500, can you now tell me how to do the old fashioned form.refresh, label.refresh, etc and get the form to respond to these refreshes... seems like I saw something different somewhere than just using the refresh call... What's the DoEvents call?
The correct call to make is invalidate(), this forces repainting.
So:
frm1.invalidate()
Normally, you shouldn't need to do this in .NET... What R U trying to do? Be back tommorrow! G-night!
So:
frm1.invalidate()
Normally, you shouldn't need to do this in .NET... What R U trying to do? Be back tommorrow! G-night!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What I do, is I declare some public variables in a module as like:
Public Main as Form
and assign them to the forms as they are loaded. Then you just call:
Main.TextBox.text = "Clicky me here"
Public Main as Form
and assign them to the forms as they are loaded. Then you just call:
Main.TextBox.text = "Clicky me here"
Also, the DoEvents has been changed. It is now practically the same as the System.Threading.Thread.Sl eep(0) command. Seems like a lot, but if you import System.Threading, you just have to call Thread.Sleep(0):
Imports System.Threading
Public Sub DoEvents()
Thread.Sleep(0)
End Sub
This is better suited for new, .Net applications. It is also compatible for Multi-threading.
Yes, the correct way to repaint a control is Object.Invalidate()
Imports System.Threading
Public Sub DoEvents()
Thread.Sleep(0)
End Sub
This is better suited for new, .Net applications. It is also compatible for Multi-threading.
Yes, the correct way to repaint a control is Object.Invalidate()
Module Module1
Dim frm1 As New Form1
Public Sub main()
frm1.Button1.Text = "This text was changed with a module"
frm1.ShowDialog()
End Sub
End Module