如何在 RichTextBox 上显示更多结果?
我是 C# 的初学者,所以请对我温柔一点。
我在尝试在富文本框中显示更多结果时遇到问题,因为它一次只能显示一个结果。但是我想在单选按钮已经重置时显示下一个结果,并且上一个结果也应该仍然在富文本框中。下面是我的编码:
for(int i=0,i<30;i++)
{
if(symptom1.Checked && symptom2.Checked)
{
Result.Text="";
Result.Text += "Your Disease is: "+"Meningiomas";
}
if(symptom7.Checked && symptom8.Checked)
{
Result.Text="";
Result.Text += "Your Disease is: "+"Pituitary Tumor";
}
}
I'm a beginner in C# so please be gentle to me .
I'm having a problem trying to display more results in rich text box because it can only display one result at once. But I would like to display the next result when the radio buttons already being resetted and the previous result should also still in the rich text box. Below is my coding:
for(int i=0,i<30;i++)
{
if(symptom1.Checked && symptom2.Checked)
{
Result.Text="";
Result.Text += "Your Disease is: "+"Meningiomas";
}
if(symptom7.Checked && symptom8.Checked)
{
Result.Text="";
Result.Text += "Your Disease is: "+"Pituitary Tumor";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果你不想删除之前的内容,删除这段代码:
我想,你想要实现的是:
这可以用这段代码来完成:
If you don't want to delete the previous content, remove this code:
I think, what you want to achieve is:
This can be done with this code:
你可以试试这个:
You can try this:
您一次只能显示一个结果的原因是您在添加下一行之前先清除文本框的当前内容。具体来说,这行代码是罪魁祸首:
由于您将
Text
属性设置为等于空字符串 (""
),因此会清除已经存在的所有内容,本质上是删除文本框。如果您只是从代码中删除该行,您应该会看到您想要的内容。下一行将附加到已经存在的内容上。然而,这只会将其粘贴到已经存在的任何东西上。
它不会将其插入新行。为此,您必须在开头插入换行符:
(请注意,
Environment.NewLine
与转义序列\r\n
相同。它只是插入一个新行。)如果您想首先清除文本框的当前内容,然后附加
for< 中的所有值。 /code> 循环,您需要将代码行添加回函数的开始,for 循环之前。从风格上来说,我也会将其写为
string.Empty
而不是""
,但这并不重要。The reason you're only able to display one result at a time is because you clear the current contents of the textbox first, before adding the next line. Specifically, this line of code is the culprit:
Since you're setting the
Text
property equal to an empty string (""
), that clears out whatever is already there, essentially erasing the textbox.If you simply remove that line from your code, you should see exactly what you want. The next line is appended to whatever is already there. However, this will simply stick it onto whatever is already there.
It won't insert it onto a new line. To do that, you have to insert a line break at the beginning:
(Note that
Environment.NewLine
is the same thing as the escape sequences\r\n
. It just inserts a new line. Same either way.)If you want to clear the current contents of the textbox first, and then append all the values in your
for
loop, you need to add the line of code back at the beginning of the function, before the for loop. Stylistically, I would also write it asstring.Empty
rather than""
, but it doesn't really matter.结果.Text="";导致您的现有数据被空文本替换,删除它,您应该对结果感到满意。
希望这有帮助。
Result.Text=""; is causing your existing data to be replaced by an empty text, remove that and you should be fine with your results.
Hope this helps.
你的意思是一个可怜的不幸者可能有症状1、2、7和8吗?因此可能同时患有两种类型的肿瘤:
干杯。基思.
PS:你的问题确实不太清楚。
Do you mean a poor unfortunate might have syptoms 1, 2, 7, and 8; and therefore probably has two types of tumor at once:
Cheers. Keith.
PS: Your question really isn't very clear.