亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我的方法不會附加這個richTextBox

為什么我的方法不會附加這個richTextBox

C#
catspeake 2021-04-29 21:17:51
我目前正在嘗試制作即時消息傳遞應用程序。有一個客戶端和一個服務器。服務器工作正常,但是由于某種原因,當我調用某個函數來更新UI時,TextBox不會將文本添加到其中。下面是我的代碼示例-在我的應用程序中,以不同的形式調用Update UI:public ChatWindow()    {        InitializeComponent();        Thread timerThread = new Thread(Main.ReceiveLoop);        timerThread.Start();    }    private void txtChatLog_TextChanged(object sender, EventArgs e)    {    }    private void btnSendMessage_Click(object sender, EventArgs e)    {        string clientReply = txtReply.Text;        string Message = "ClientMsg§" + clientReply;        var time = DateTime.Now;        txtChatLog.AppendText($"{time} client: {clientReply}");        txtChatLog.AppendText(Environment.NewLine);        Main main = new Main();        main.ChatResponse(Message);        txtReply.Text = "";    }    public void UpdateChatLog(string message)    {        var time = DateTime.Now;        string newMessage = message.Split('$')[1];        string messageToDisplay = $"{time} Server: {newMessage}";        MessageBox.Show(messageToDisplay);        txtChatLog.AppendText(messageToDisplay);        txtChatLog.AppendText(Environment.NewLine);    }    private void ChatWindow_Load(object sender, EventArgs e)    {    }正如我用messagebox.show();檢查的那樣,客戶端挑釁地從服務器接收消息。同樣,當按下發送消息按鈕時,富文本框也會更新。但是由于某種原因,它不會通過UpdateChatLog方法進行更新。任何幫助將非常感激。
查看完整描述

2 回答

?
侃侃無極

TA貢獻2051條經驗 獲得超10個贊

嘗試刷新文本框:txtChatLog.Refresh()


查看完整回答
反對 回復 2021-05-08
  • 2 回答
  • 0 關注
  • 203 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號