winform界面交互

1.button_click事件添加await

private async void buttonConnect_Click(object sender, EventArgs e)
        {
            await Task.Run(() => commondConnect());
            try
            {
                
                MessageBox.Show("连接成功!");
            }
            catch (Exception ex)
            {
                
                MessageBox.Show(string.Format("连接失败!{0}", ex.Message));
            }
        }

 

2.添加提示项

private void commondConnect()
        {
            this.statusStrip1.Invoke(new Action(() => {
                this.statusStrip1.Items[0].BackColor = Color.FromArgb(255, 202, 81, 0);
                this.statusStrip1.Items[0].ForeColor = Color.White;
                this.statusStrip1.Items[0].Text = "正在连接......";
            }));
        }

 

posted @ 2022-02-18 16:16  驼七  阅读(32)  评论(0)    收藏  举报