且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#从另一个类添加控件到窗体

更新时间:2023-12-06 10:41:34

这不是完全清楚你想要做什么。这听起来像你想从Player类控件添加到您是从这样的调用形式:

It's not entirely clear what you're trying to do. It sounds like you want to add controls from the Player class into the form that you're calling from like this:

public class Form1 : Form
{
    public void SomeMethod()
    {
        Player player1 = new Player(this);
    }
}

public class Player()
{
    public Player(Form form)
    {
        Textbox tb = new Textbox();
        form.Controls.Add(tb);
    }
}