winform,这句代码什么作用this.components = new System.ComponentModel.Container();

threadroc 2015-10-12 05:34:14
我默认创建一个winform窗体,都会带这句话.
this.components = new System.ComponentModel.Container();
但是,当我拖入一些控件的时候,再看代码,这句话,没了.

时有时无.
如果有这句话的时候,我拖入我的自定义控件
public CtrlAttachment(IContainer container)
{
InitializeComponent();
}
会自动调用这个构造方法:xxx=new CtrlAttachment(this.compoents);

没有这句话,就会调用默认构造方法: xxx=new CtrlAttachment();

请问:this.components = new System.ComponentModel.Container();
这句代码何时会出现.

我看有人说,窗体拖入组件的时候,这句代码就有了,可我拖入好几个组件例如Timer,还是没有自动生成这句代码呀.

...全文
655 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
threadroc 2015-10-12
  • 打赏
  • 举报
回复
引用 3 楼 shingoscar 的回复:
有写
namespace TestWinFormApp
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

public UserControl1(IContainer container)
{
}
}
}


引用 3 楼 shingoscar 的回复:
有写
namespace TestWinFormApp
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

public UserControl1(IContainer container)
{
}
}
}


引用 3 楼 shingoscar 的回复:
有写
namespace TestWinFormApp
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

public UserControl1(IContainer container)
{
}
}
}


引用 3 楼 shingoscar 的回复:
有写
namespace TestWinFormApp
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

public UserControl1(IContainer container)
{
}
}
}


好吧,好用了,和你一样了,重启了一下开发工具好了. 估计是开发工具bug吧...
Poopaye 2015-10-12
  • 打赏
  • 举报
回复
有写
namespace TestWinFormApp
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

public UserControl1(IContainer container)
{
}
}
}
threadroc 2015-10-12
  • 打赏
  • 举报
回复
引用 1 楼 shingoscar 的回复:
我的情况是只要拖入带IContainer构造函数的,无论是控件还是组件,都会出现那句new
移除掉以后就没了


那,你除了IContainer构造函数,有写默认构造函数吗?
Poopaye 2015-10-12
  • 打赏
  • 举报
回复
我的情况是只要拖入带IContainer构造函数的,无论是控件还是组件,都会出现那句new
移除掉以后就没了
ComponentOne Studio for WinForms 2013 v1 1/5 共五个压缩文件,请全部下载后解压 Part of: Ultimate | Enterprise 65+ .NET Windows Forms controls, including the ones you can't get anywhere else. Generate a grid with a million rows to a chart with unlimited points. Over 65 .NET Windows Forms controls, including the ones you can't get anywhere else. ComponentOne Studio® for WinForms controls come packed with smart, code-free designers, endless built-in features, superior flexibility, and the outstanding assurance that these controls will stand the test of time. 2013 v1 Now Available! Download the 2013 v1 update to access the new TileControl to achieve a Windows 8 look and feel in your desktop apps as well as feature enhancements for Reports, Editor, and Scheduler. See the what's new details. What's Inside? Chart FlexGrid PDF Reports Scheduler True DBGrid BarCode DataExtender DataObjects DockingTab DynamicHelp Editor Excel Flash GanttView Gauges Input InputPanel List Menus and Toolbars NavBar OutBar Ribbon Sizer SpellChecker SplitContainer SuperTooltip TopicBar Win7 Pack Zip Show Less Why use Studio for WinForms? Best Selling Grids in the Market Best Selling Grids in the Market Since 1991 ComponentOne has been offering two award-winning grids for creating Windows Client applications: FlexGrid and True DBGrid. Each is designed to give you the best performance and features for different types of applications. Both grids offer many out-of-the-box features like filtering, hierarchical data-binding, grouping, printing, and exporting to Microsoft Excel without any additional coding required. See a comparison. All-in-one Reporting Solution All-in-one Reporting Solution With a rich object model for generating reports, several UI controls for previewing, and a report designer for creating and designing reports, Reports for WinForms is your all-in-one reporting solution. Generating cutting-edge reports for your .NET applications has never bee

111,092

社区成员

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

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

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