C#-RichTextBox-无法正常工作 [英] C# - RichTextBox - Won't Work
本文介绍了C#-RichTextBox-无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好,所以这是我必须打开rules.txt文件的代码....每当我尝试编辑richtextbox时,它总是会使程序崩溃...任何想法....错误列表..
Ok, so here is the code I have to open my rules.txt file.... Whenever I try and edit the richtextbox it always crashes the program... Any ideas why.... Nothing showed up in the error list..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace McMayhem.GUI
{
public partial class TextFiles : Form
{
public TextFiles()
{
InitializeComponent();
}
private void txtRules_TextChanged(object sender, EventArgs e)
{
if (File.Exists("Rules.txt"))
{
txtRules.Text = "Rules for " + Server.Version + ":";
foreach (string line in File.ReadAllLines(("Rules.txt")))
{
txtRules.AppendText("\r\n " + line);
}
}
}
}
}
推荐答案
对于软件开发人员来说,没有崩溃"之类的东西.软件开发人员使用Debugger和总是可以看到发生了什么.您需要做的第一件事是停止做您正在做的事情,成为一名软件开发人员.今天,不是明天!
现在,只需考虑您的工作!您没有显示如何设置事件处理程序(谁知道txtRules_TextChanged
的含义;没有此类事件),但是通过此方法的名称,您可能会猜测它用作TextChanged
事件的处理程序.您的控件textRules
.为什么选择RichTextBox
?它应该只是TextBox
.没关系,让我们看看.每次更改时,您都会阅读一些文本并将其附加到相同文本框中!它再次触发同一文本框的TexChanged
,然后…正确无限递归 .
我不知道为什么要这么做,但这就是你搞砸的方式.整个事情都没有道理.您的最终目标是什么? (如果您不想要,请不要回答:-).)
—SA
For a software developer, there is not such thing as "crash". A software developer uses Debugger and always can see what''s going on. First thing you need to do is to stop doing what you''re doing and become a software developer. Today, not tomorrow!
Now, just think what you do! You do not show how your event handler is set up (who knows whattxtRules_TextChanged
means; there is no such event), but by the name of this method one could guess that this is used as a handler of theTextChanged
event of your controltextRules
. WhyRichTextBox
? It should be justTextBox
. No matter, let''s see. On every change, you read and append some text to the same text box! It triggersTexChanged
of the same text box again and… right, infinite recursion.
I have no idea why doing this, but this is how you screw up. Whole thing makes no sense. What was your ultimate goal? (Don''t answer if you don''t want :-).)
—SA
这篇关于C#-RichTextBox-无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文