• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2083
  • Last Modified:

Need to update textbox on the main form from another class

I have a windows application form which has a textbox. I need to update the textbox on the main form from another class.
If I have a  button and textbox.when I click the button, it creates an object of another class and calls the method of the class. Asthe method is running it is looping through rows. It sends a message as it completes each row. I want that message to be displayed in th textbox.
Do we need to use delegates??/
Can you please provide me a solution for this.
0
MRManthani
Asked:
MRManthani
  • 2
1 Solution
 
Bob LearnedCommented:
You would need an instance of the main form, and then set the Modifiers to internal for the TextBox.
0
 
MRManthaniAuthor Commented:
I have created instance of the main from.It is sending the messages.but the form gets frozen. I am not able to see it. it may be because the application is still running.
is there any way to see it updating when the application is running.
0
 
Anurag ThakurTechnical ManagerCommented:
yes delegates and events is the way to go in this scenario

create a delegate and an event in childclass

public delegate void SearchDelegate (string screenName, string parameter);
public event SearchDelegate SearchEvent;

in the method that you call add this
if (SearchEvent != null)
{
     SearchEvent ();
}

in the main form subscribe to the event as (just an idea)
this.childclass1.SearchEvent += new childclass.SearchDelegate(ShowScreen);

this will call your function and then you can handle your cases accordingly
0
 
Anurag ThakurTechnical ManagerCommented:
you need to pass the string value which u need to update to the text box in the delegate and then use that in the main form
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now