在窗体运行的时候,LOAD控件

apple1980 2004-04-22 02:50:10
想实现,在窗体运行的时候,增添控件,如何实现。

Button newbutton=new Button();
int localy=0;
int localx=0 ;
newbutton.Location=new Point (localy,localx);
newbutton.Name ="wq";
this.Controls.Add(newbutton);
想把这段代码,先写进一个类里,之后,在窗体的构造函数里调用这个类,可是不行。
...全文
29 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
apple1980 2004-04-27
  • 打赏
  • 举报
回复
OK,对面的老大,加载上了控件,可是没有事件呀,怎么写订阅事件的代码。是不是有点问的太多了。不好意思呀
brightheroes 2004-04-22
  • 打赏
  • 举报
回复
try


下面这句话放在构造函数的最下面(如果你有其他操作的话)
AddControl.addBUtton(ref this);
apple1980 2004-04-22
  • 打赏
  • 举报
回复
是调用AddControl.addBUtton(Form1);(刚才写错了)
apple1980 2004-04-22
  • 打赏
  • 举报
回复
我说,上面的老大,我在,窗体的构造函数里,调用objAddControl.addBUtton(Form1); 怎么出错,
。From1"表示类,此处应为变量
brightheroes 2004-04-22
  • 打赏
  • 举报
回复
try


class AddControl
{

public static void addBUtton(ref Form varForm)
{

Button newbutton=new Button();
int localy=0;
int localx=0 ;
newbutton.Location=new Point (localy,localx);
newbutton.Name ="wq";
varForm.Controls.Add(newbutton);

}
}

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧