本文介绍了使用委托参数在C#中的类和形式之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从一个类传入值到RichTextBox。这里是我的代码。我必须传递值到任何工具像文本框,列表框,但我不知道如何。我必须使用代理将md值传递到两个方法并进入同一个富文本框。

I have to pass value into RichTextBox from a class. Here is my code. I have to pass values into any tools like textbox, listbox but I don't know how. I have to use delegates to pass md value to both methods and into the same richtextbox.


 namespace delegateEx2
{
    public class MyClass : Form1
    {
        delegate void MyDelegate(string MyString);

        public void ShowThoseMessages()
        {
            MyDelegate md = new MyDelegate(log1);
            md += log2;
            md("Error Log Text");
        }

        public void log1(string message) {

            //what can I write here to pass the md into the RichTextBox on Form1.cs
            //I tried something like Systems.Windows.Form.rtxblog but did not work
            //......................................


        }

        public void log2(string message2)
        {

          //.....................................

        }

    }


推荐答案

简单的问题是更改richtextbox声明中的修饰符。
你可以在Form1.designer.cs中找到声明。
将修饰符从private更改为protected,然后您可以从log1方法访问richtextbox。

The simple questions is to change the modifier in your richtextbox declaration.You can find the declaration in Form1.designer.cs.Change the modifier from private to protected, then you can access the richtextbox from log1 method.

这篇关于使用委托参数在C#中的类和形式之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:06
查看更多