C# adding control from another class

风格不统一 提交于 2019-12-25 04:14:41

问题


I want to add form controls dynamically to my form from another class which inherits the form class. Everything works fine but it does not add the controls at run time.

Here is my sample code:

namespace Namespace1
{
 public partial class Form1 : Form
   {
    .....

  }

 .......
 }// end of Namespace1

namespace Namespace2
{
public class1:Form1
{
public Button button = new Button();

public void method1()
  {
   button1.Name="button1";
  //flowlayoutcontrol1 is a public control on Form1
  flowlayoutcontrol1.Controls.Add(button1);
  }

} }

来源:https://stackoverflow.com/questions/16338447/c-sharp-adding-control-from-another-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!