如何选择多行文本框的文本顺序? [英] How can I select the text order of a multiline textbox?

查看:74
本文介绍了如何选择多行文本框的文本顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多行文本框,它接收来自不同类的值,我希望每行都添加在顶部而不是底部,我该怎么做?



我有一个计时器,每秒向列表添加一个日期和一个随机数。它被分析,并有一个文本框,说明是保留还是删除。







在我检查我的值的类中:

public string Log {get;组; }

Log + =example 1;

Log + =example 2;

Log + =example 3; < br $> b $ b





在MainWindowXAML.cs中我有:

textbox.Text = classinstance.Log;



我进入文本框:

示例1

示例2

示例3



我想要

示例3

示例2

示例1

I have a multiline textbox that receives values from a different class, and I want that every line is added on top instead of the bottom, how can I do that?

I have a timer that adds a date and a random number to a list every second. It is analysed and there is a textbox that says if that point is keep or deleted.



In a Class where i check the values I have :
public string Log { get; set; }
Log + = "example 1";
Log + = "example 2";
Log + = "example 3";



In the MainWindowXAML.cs i have:
textbox.Text = classinstance.Log;

And I get in the textbox:
"example 1
example 2
example 3"

And I want
"example 3
example 2
example 1"

推荐答案

明显的解决方案是在类中以正确的顺序添加它们;-p


但是,您可以使用字符串的 Insert 方法,例如
Well the obvious solution would be to add them in the correct order within the class ;-p

However, you can use the Insert method of a string e.g.
Log = "example 1" + "\r\n";
Log = Log.Insert(0, "example 2" + "\r\n");
Log = Log.Insert(0, "example 3" + "\r\n");





我也有责任指出你不应该使用<字符串上的code> + = - 它们是不可变的,因此每次实际创建一个新字符串。更好的是使用 StringBuilder



I also feel duty-bound to point out that you shouldn't use += on strings - they are immutable so you are actually creating a new string each time. Better is to use StringBuilder


这篇关于如何选择多行文本框的文本顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆