好吧,我一直在尝试随机化我的richtextbox的行,现在它开始困扰我,因为我正在使用随机但它不起作用......当我使用它时,它会多次重复一些行,并且根本不包括一些...
但这对我一点帮助都没有。
RichtextBox rtb = new RichTextBox();
Random R = new Random();
int y;
rtb.Text = "";
for (int i = 0; i < richTextBox1.Lines.Length; i++)
{
y = R.Next(0, richTextBox1.Lines.Length);
rtb.Text = rtb.Text + richTextBox1.Lines[y].ToString() + "\r\n";
}
richTextBox2.Text = rtb.Text;
例如,如果我输入,
Lorem ipsum dolor sit amet, consectetur adipiscing elit。Nam in aliquam enim。Proin 在 lacus magna。Nam bibendum, augue non semper fringilla, ante est interdum ipsum, a egestas urna dolor vel risus。Phasellus eget dui non augue pretium ullamcorper at ac Tellus。Sed mattis risus 坐 amet metus dictum egestas。Phasellus tempus blandit enim,ac congue urna bibendum sed。Sed iaculis pulvinar dui vel tristique。Etiam justo metus, consequat in pellentesque eu, eleifend id nunc。
它给了我,
Sed mattis risus 坐 amet metus dictum egestas。Phasellus tempus blandit enim,ac congue urna bibendum sed。Nam bibendum, augue non semper fringilla, ante est interdum ipsum, a egestas urna dolor vel risus。Sed mattis risus 坐 amet metus dictum egestas。Phasellus tempus blandit enim,ac congue urna bibendum sed。Sed iaculis pulvinar dui vel tristique。Etiam justo metus, consequat in pellentesque eu, eleifend id nunc。Lorem ipsum dolor sit amet, consectetur adipiscing elit。Nam in aliquam enim。Proin 在 lacus magna。
重复一行,错过了一行……文本越长,它出现的频率越高。
我做 C# 的时间不长,如果这很简单,很抱歉。:/