Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginners question... calling public methods 1

Status
Not open for further replies.

AHint

Programmer
Sep 12, 2003
20
GB
I'm new to C# and have a fundamental question I'm sure you could all answer in your sleep.

I have a form and on clicking a button instantiate a new class and loop through a series of files. After each file I want to update a progress bar on my form to show how many files have been processed. How can I do this? Can I use a public method on my form or is this just not possible. I know that if I'm using a child mdi I can use a cast to call back up to the parent to get a public method but how do I do it in this case?

Thanks all!!
 
The principle is to create a class with a refernce to the object tah created the class.


namespace Test
{
class MyClass
{
//myForm holds a reference to the mainform.
private Form myForm;

//f is the form thats create MyClass
public MyClass(Form f)
{
//myFrom gets the refernce to the MainForm
myForm = f;
}

public void loop()
{
for(int i = 0; i < 10; i++)
{
//And finally you can call a public method in the MainForm.
myForm.MyMethod();
}
}
}
}
 
Worked like a charm - thanks very much!!! Pink star for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top