如何在richtextbox中的多个文本框中打印值 [英] how to print values in multiple textboxes in richtextbox

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

问题描述

我有一个我有 10 个文本框的地方,它们被命名为 textbox1、textbox2 等等.我想在单个富文本框中打印所有文本框中的值.有什么办法可以做到这一点.我目前的做法是:

i have a from where i have 10 textboxes and they are named as textbox1,textbox2 and so on. I want to print the values in all the textboxes in a single rich-textbox. is there any way i can do that. the way i am doing it currently is:

richTextBox1.Text = label1.Text + "\t:\t" + textBox1.Text + "\n" + label1.Text + "\t:\t" + textBox1.Text;

但是正如你所看到的,为所有文本框输入它会非常麻烦.

but as you can see it will be very cumbersome to type it for all the textboxes.

推荐答案

for(int i = 1; i < 11; i++){
   yourRichTextBox.Text += string.Format("{0}\t:\t{1}\r\n",
    yourForm.Controls["label" + i].Text, yourForm.Controls["textBox" + i].Text);
}

注意:如果您在表单类中使用代码,只需将 yourForm 替换为 this 或简单地删除 yourForm.

NOTE: if you use the code inside your form class, just replace yourForm with this or simply remove yourForm.

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

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