开发者

Automatic label text update in C#

If I set the value of a string in one form and then display in label on another form by clicking a "update" button on the second form. This part works.

I would like to know how I can make the label update it's text value after the first form closes.

If I try doing with:

public static void Subject_select() {

    L_Subject.Text = Global.Subject;

    }

And then running this with:

    msinForm.Subject_select();

Then it throws the error: An ob开发者_运维问答ject reference is required for the non-static field,method, or property 'app1.mainForm.L_Subject'


I suppose better approch is create Global event and fire it when in a first form text was changed and than in second form subscribe to an event and change text in event handler.

Check about global events here. If you will go through static events beware of memory leaks.


The best way would be to use FormClosed event of second form. subscribe to it from the first form. In event handler you should update your label

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜