在另一个类的窗体中添加的列表框中编写 [英] Writing in Listbox added in Form in Another Class

查看:60
本文介绍了在另一个类的窗体中添加的列表框中编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI ...

我是C#的初学者,有个问题.

这是来自班级的

HI...

I''m a beginner in C# and have a question.

This is the from class

namespace WindowsFormsApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
}


这是名为Class1 ...的工作类.


This is the working class named Class1...

namespace WindowsFormsApplication
{
    class Class1
    {
    }
}


我想修改从Class1向列表框添加的文本吗?


I want to modifer added text to listbox from Class1? How can I do it?

推荐答案

您需要以某种形式实现一些非私有(内部)方法/属性;更好的是,以执行此操作的形式实现一些接口.该接口对于Class1应该是可见的,在所有情况下,您都需要Class1需要形成实例引用.

有关我的方法,其他选项和讨论的更多详细信息,请参见:
You need to implement some non-private (internal) method/property in the form; better yet, implement some interface in the form which does that. The interface should be visible to Class1, in all cases, you need your Class1 need to have to form instance reference.

For more detail on my approach, other options and the discussion, see this: How to copy all the items between listboxes in two forms[^].

This discussion is about two different forms, but it covers your case as well: one form and some separate class.

—SA


这篇关于在另一个类的窗体中添加的列表框中编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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