开发者

Making status visible in main form from another 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 line:

Main status = new Main();

Creates a new Main form, not your original form (and you don't see it as you don't Show() it).

You need a reference to the original Main form before you can set properties on it, though doing so will cause coupling between your different forms (not a good thing).

One way to achieve what you want is to have an event handler on the second form that fires when the button is clicked and subscribe to it from the Main form, where you would set the status.


Good old static globals (remember vb?)

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";
    }
}

}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜