How does one access a control from a static method?

前端 未结 10 1941
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 12:50

I have an application in C# .NET which has a MainForm and a few classes.

One of these classes receives incoming data messages from a network. I need to

10条回答
  •  清歌不尽
    2020-11-30 13:42

    private void FormMain_Load(object sender, EventArgs e)
    {
        TheIncomingDataClass.SetupControl(textBox1);
    }
    
    public class TheIncomingDataClass
    {
        public static TextBox textbox = new TextBox();
        public static void SetupControl(TextBox txt)
        {
            textbox = txt;
        }
        public void IncomingMessage(string message)
        {
            textbox.Text = message;
        }
    }
    

提交回复
热议问题