![](/img/trans.png)
[英]Convert console.writeline to RichTextBox.AppendText() c#
[英]Getting different results using Debug.Writeline vs. RichTextBox.AppendText
我想知道如果任何人都可以解釋為什么當我用下面的代碼我得到不同的結果。 為了進一步說明,我使用的是在C#中創建的dll,它是一個rcon框架。 richtextbox顯示3行,然后將不再顯示,而我的調試控制台繼續從rcon連接獲取數據。
我正在使用:
Private Shared Sub HandleMessage(args As BattlEyeMessageEventArgs)
Debug.WriteLine(args.Message)
Form1.RichTextBox3.AppendText(args.Message & vbNewLine)
Form1.RichTextBox3.SelectionStart = Form1.RichTextBox3.TextLength
If args.Message = "Connected!" Then
Form1.Button3.Enabled = True
End If
End Sub
如果有幫助,這里是EventHandler的C#代碼:
using System;
namespace BattleNET
{
public delegate void BattlEyeMessageEventHandler(BattlEyeMessageEventArgs args);
public class BattlEyeMessageEventArgs : EventArgs
{
public BattlEyeMessageEventArgs(string message)
{
Message = message;
}
public string Message { get; private set; }
}
}
private delegate void UpdateRichTextBox3Delegate(RichTextBox3 textBox, string text);
private void UpdateRichTextBox3(RichTextBox3 textBox, string text){
if(textBox.InvokeRequired){
textBox.Invoke(new UpdateRichTextBox3Delegate(UpdateRichTextBox3),new object[]{textBox, text});
return;
}
textBox.AppendText(String.format("{0}{1}", text,Environment.NewLine));
}
檢查RichTextBox3是否不需要在更新之前先被調用。
調用UpdateRichTextBox3(Form1.RichTextBox3, "some text to append");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.