parabellum
asked on
Access and change control from another class.
Hello.
Say i have a Form1(). and a Textbox1 in it. Now i have a class named "myclass" in another myclass.cs file. (myclass is public). and myclass has a function named foo()
myclass is performing some asynchronous operations in the background. I want foo() to update
textbox1.
I know i need to use delegates, but can you help me how to do that with a sample ?
Thanks.
Say i have a Form1(). and a Textbox1 in it. Now i have a class named "myclass" in another myclass.cs file. (myclass is public). and myclass has a function named foo()
myclass is performing some asynchronous operations in the background. I want foo() to update
textbox1.
I know i need to use delegates, but can you help me how to do that with a sample ?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. But how will i raise the event from Foo() ?
For example, say Foo is accepting a input parameter int input:
Foo(int input).
if(input==5)
Invoke the textbox ====> How will il invoke it ?
Foo is firing an event which is subscribed by Form1 through myclass_OperationComplete method. It then set the value in the required textbox.
public void Foo(int input)
{
if (input == 5 && OperationComplete != null)
OperationComplete("OperationCompleted");
}
ASKER
Oooh how could i miss that ... Thanks a lot :)
Open in new window