|
-
Oct 31st, 2002, 12:43 PM
#1
Thread Starter
Registered User
Help: HowTo Acces a control from within a class
Hello again!
I fear this i a pretty easy one
I got a progressbar on my form which needs to be updated from time to time. My problem is that the progress is being done in a class in another namespace. How could I change the Value of the progressbar from that class? I just don't see a way to access it.
-
Oct 31st, 2002, 12:49 PM
#2
PowerPoster
You could either pass a reference of the progress bar into your class or you could create a delegate which will callback to a routine on the form that updates the progress bar.
-
Oct 31st, 2002, 02:49 PM
#3
Thread Starter
Registered User
I think I could need an example, I've never used delegates before, neither did I create any references, no matter what I try it does not work. I end with a static void from which I can't access any controls on the form.
-
Oct 31st, 2002, 07:28 PM
#4
PowerPoster
Does this help at all?
Code:
private void button1_Click(object sender, System.EventArgs e)
{
DoSomething mySomething = new DoSomething("Hello World",new DoSomething.UpdateControl(DisplayText));
}
private void DisplayText(string myText)
{
this.textBox1.Text = myText;
}
}
public class DoSomething
{
string message;
public delegate void UpdateControl(string message);
public DoSomething(string message,UpdateControl myUpdate)
{
this.message = message;
myUpdate(message);
}
}
You could also raise events.
-
Nov 1st, 2002, 06:02 AM
#5
Thread Starter
Registered User
It helps , very much indeed, thank you!
-
Nov 1st, 2002, 08:09 AM
#6
Thread Starter
Registered User
Ok, Iv'e done that! The value is passed to the progressbar!
BUT WHY IS THE PROGRESSBAR NOT REFRESHING?
I've tried to write the value into a textbox for checking, but the text alsow won't change . But when I put a messagebox after that like MessageBox.Show (textBox1.Text, "My Application", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
It will show the the correct value, though the text in the textbox is not the textBox1.Text which the MessageBox says!
Is there something needed to refresh the stuff?
Last edited by Olly; Nov 1st, 2002 at 09:28 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|