开发者

status message on main form

I have multiple forms based application in that I have some entry forms, if in entry form filled开发者_开发百科 and submit button clicked then I want to display submitting status in main form status-strip

I used like this but not working

Main status = new Main();
status.workStatusStrip.Text = "Submitted Successfully";

sample code preferred..


this will help you

WindowsFormsApplication1
{
     public partial class Form1 : Form
    {
        static Label statusMessageLabel;
        public static string StatusText { set { statusMessageLabel.Text = value; } }

        public Form1()
        {
            InitializeComponent();
            statusMessageLabel = label1;

            // from anywhere ->
            Form1.StatusText = "a message";
        }
    }

}


You have two options, and what option to choose can't be said from your question.

First:

Let your 'data entry form' derive from some base class that defines delegate for status change and an event for that delegate like this

public delegate void StatusChange(string Status);
public event StatusChange OnStatusChange;

Now in your main form subscribe to that event for each data entry form created like this

SomeDataEntry de = new SomeDataEntry();
de.OnStatusChange += StatusChanger;
de.Show(); //  or whatever

in form do

if (OnStatusChange!=null) {
    OnStatusChange("status text");
}

and in main form do

void StatusChanger(string Status)
{
    status.Text=Status;
}

Second:

Do something like Chandan suggested, but please don't make the member static, instead have an interface, with one member, derive from it, pass the interface to the data entry form, and call its method to update status text from the data entry form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜