如何根据复选框将文本打印到RichTextBox. [英] How to print text to RichTextBox depending on a checked box.

查看:91
本文介绍了如何根据复选框将文本打印到RichTextBox.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有一个复选框,其中有两个选项.是和否.单击按钮后,如果复选框中的输入为否,则文本应显示为"Client is not ...",但是如果选中"Yes"框,则:"Client is ...."能做到吗?谢谢.

我已经使用以下方法成功打印了复选框本身的文本:

I have a checklistbox on my form with two options. Yes and No. On a button click, if the checklistbox has an input of No, then text should read "Client is not...," but if the Yes box is checked, then: "Client is ...." how can this be achieved? Thank you.

I have already successfully printed the text of the checkbox itself using:

string text = "";
            foreach (var item in checkedListBox1.CheckedItems)
            {

                text += item.ToString() + ",";
            }
            richTextBox2.Text += text;





好的,我尝试使用组合框.而且更容易:





Ok, I tried using a combo box instead. And it is much easier:

if (comboBox1.Text == "Yes")
            {
                richTextBox2.Text += "Yes, the client is ambulatory.";
            }
            else
            {
                if (comboBox1.Text == "No")
                {
                    richTextBox2.Text += "No, the client is not ambulatory.";
                }
                else
                {
                    richTextBox2.Text += "[ERROR: PLEASE ENTER EITHER YES OR NO FOR 'AMBULATORY']";
                }
            }



但是我有一个问题,如果用户要键入是"或否"而不是进入下拉菜单,则必须确保Y或N大写.如何使if语句检查是"和是"?
谢谢.



But i have a problem, if the user wants to type "Yes" or "No" instead of going to the drop down menu, he must make sure that the Y or N is capitalized. How can I make the if statement check for "Yes" and "yes"?
Thank you.

推荐答案

此外,您应该知道在构造字符串时应该使用StringBuilder ,因为每次对字符串进行任何更改时,都需要使用全新的必须创建对象.

Also you should know that you should be using the StringBuilder when constructing strings because each time you make any change to a string, a complete new object has to be created.

StringBuilder sb = new StringBuilder() ;
foreach (var item in checkedListBox1.CheckedItems)
{
  sb.Append (item.ToString() + ",");
}
richTextBox2.Text += sb.ToString();


这篇关于如何根据复选框将文本打印到RichTextBox.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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