从一个richtextbox获取文本框中的值 [英] get value in textboxes from one richtextbox

查看:91
本文介绍了从一个richtextbox获取文本框中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有5个文本框和5行的richtextbx。如何在第一个文本框中获取richtextbox的第一行文本,在第二个文本框中获取richtextbox的第二行文本,依此类推。



i have 5 textboxes and a richtextbx of 5 line. how can i get 1st line text of richtextbox in 1st textbox, 2nd line text of richtextbox in 2nd textbox, and so on.

private void myRichTextBox_Click(object sender, EventArgs e)
        {
            string[] lines = richTextBox1.Lines;
            if (lines.Length >= 5)
            {
                myTextBoxForLineOne.Text = lines[0];
                myTextBoxForLineTwo.Text = lines[1];
                myTextBoxForLineThree.Text = lines[2];
                myTextBoxForLineFour.Text = lines[3];
                myTextBoxForLineFive.Text = lines[4];
            }
        }













假设我们将myTextBoxForLineTwo留空,然后在myRichTextBox中显示空格。

如何从myRichTextBox中删除此空格。







suppose if we left myTextBoxForLineTwo blank then it shows blank space in myRichTextBox.
how to remove this blank space from myRichTextBox.

推荐答案

有很多方法可以做到这一点 - 最明显的是:

There are quite a lot of ways to do that - the most obvious is:
List<string> nonBlankLines = new List<string>();
foreach (string s in lines)
   {
   if (!string.IsNullOrWhiteSpace(s)) nonBlankLines.Add(s);
   }

但你可以使用其他六种方法中的任何一种。

But you could use any of half a dozen other methods.


hi,



试试这段代码...,





为5个文本框编码创建控制数组。



在课堂上声明文本框控件数组。

private TextBox [] textBoxes;





并按照以下代码..





try this code...,


create control array in coding for your 5 textboxes.

declare textbox control array in class.
private TextBox[] textBoxes;


and follow the below code..

string[] lines = richTextBox1.Lines;
textBoxes = new TextBox[] { myTextBoxForLineOne, myTextBoxForLineTwo, myTextBoxForLineThree, myTextBoxForLineFour, myTextBoxForLineFive};
int txtboxCnt = 0;

if (lines.Length >= 5)
{
    for  (int i=0; i< lines.Length; i++)
    {
        if (lines[i].Trim() != "")
        {
            textBoxes[txtboxCnt].Text = lines[i];
            txtboxCnt++;
        }
    }
}









问候,



Prakash.T





regards,

Prakash.T


这篇关于从一个richtextbox获取文本框中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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