如何在Forms以外的类中的RichTextBox中显示文本? [英] How to show text in a richtextbox from a class other than class Forms?

查看:65
本文介绍了如何在Forms以外的类中的RichTextBox中显示文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在类的RichTextBox中显示错误.我在Forms1类中实现了此功能

 公共  void  showError(字符串错误)
{
     .richTextBox2.AppendText(错误);
} 



并在某个班级中称呼它

Forms1 f= new Forms1();
f.showError("Redecalaration of " + N);



但这并不会在richtextbox.i中显示错误,请对其进行调试.在表单类中,richtextbox的文本值发生更改但未在box.plus中显示,我在许多地方直接编写this.richTextBox2.AppendText("Hi"),直接在richtextbox中添加了错误,并且错误显示得很完美. ="h2_lin">解决方案

我不确定您是否遇到任何错误.你没提到那件事.如果您的问题未显示Forms1,则以下为解决方法.并确保表单名称为Forms1.

 Forms1 f =  Forms1();
f.showError("  + N);
f.Show();
// 或f.ShowDialog();  


让我知道您的反馈.


i have to show errors in a richtextbox from a class. i made this function in Forms1 class

public void showError(string error)
{
    this.richTextBox2.AppendText(error);
}



and call it in some class

Forms1 f= new Forms1();
f.showError("Redecalaration of " + N);



but this doestnt show error in richtextbox.i debug it. value of text of richtextbox changes but not showing in the box.plus while in the forms class, i add error in the richtextbox directly by writing this.richTextBox2.AppendText("Hi") at many places and error shows perfectly.

解决方案

I am not sure you are getting any error or not. You didn''t mention that. If your problem is not showing the Forms1 then following is the workaround. And make sure that the form name is Forms1.

Forms1 f= new Forms1();
f.showError("Redecalaration of " + N);
f.Show();
//or f.ShowDialog();


Let me know your feedback.


这篇关于如何在Forms以外的类中的RichTextBox中显示文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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