gpt4 book ai didi

c# - RichTextBox new Text append on top

转载 作者:行者123 更新时间:2023-11-30 13:58:51 24 4
gpt4 key购买 nike

我的 C# 应用程序中有一个 RichtTextBox,它向用户显示日志。问题是新插入的文本 append 在旧文本下面,但我想在旧文本之上 append

例如,当我附加文本“Newtext”时,它看起来像这样:

RichtTextBox:

|---------------------
|Oldtext |
|Newtext |
|---------------------

但它需要看起来像这样:

富文本框:

|---------------------
|Newtext |
|Oldtext |
|---------------------

这是我用来填充我的 RichTextBox 的代码:

public void DisplayLog(string logtext)
{
if (logtext != "")
{
if (this.txtLog.InvokeRequired && !txtLog.IsDisposed)
{
Invoke(new MethodInvoker(delegate()
{
txtLog.AppendText(DateTime.UtcNow + ": " + logtext + "\n");
}));
}
else if (!txtLog.IsDisposed)
{
txtLog.AppendText(DateTime.UtcNow + ": " + logtext + "\n");
}
}
}

有人可以帮帮我吗?

回答:

Inserting at top of richtextbox

最佳答案

使用插入

txtLog.Text =  txtLog.Text.Insert(0,DateTime.UtcNow + ": " + logtext + "\n");

关于c# - RichTextBox new Text append on top,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15132206/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com