在InitializeComponent()的非常简单的定义;方法 [英] Very Simple definition of InitializeComponent(); Method

查看:2388
本文介绍了在InitializeComponent()的非常简单的定义;方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力通过深入浅出C#的书,已经用在InitializeComponent();方法多次。

I have been working through the Head First C# book and have used the InitializeComponent(); method several times.

这方面的一个例子是关于党计划练习,我创建了一个名为DinnerParty.cs类,然后在Form1.cs中使用此代码

An example of this is on the Party Planner exercise I created a class called DinnerParty.cs and then used this code in the Form1.cs

public Form1()         
        {        
            InitializeComponent(); 
            dinnerParty = new DinnerParty() { NumberOfPeople = 5 };
            dinnerParty.SetHealthyOption(checkBox2.Checked);
            dinnerParty.CalculateCostOfDecorations(checkBox1.Checked);
            DisplayDinnerPartyCost();
        }



我的问题是,究竟是什么初始化组件的方法做。我的理解是我定义的晚餐会上类的新对象或实例和设置所有的值,到目前为止,我已经假定的InitializeComponent()是一种说使用下面的设置我的字段的值:

My Question is, what exactly is the Initialize Component method doing. My understanding is that I am defining a new object or instance of the DinnerParty class and setting up all the values, so far I have assumed that InitializeComponent() is kind of saying "Set up values of my fields using the following:"

我能请有一个基本的东西我可以让我的头周围的定义。我看过关于这个以前的职位和答案,一切都太复杂。我将迎来最容易理解的反应,仍然有关键信息作为回答。

Could I please have a BASIC, something I can get my head around definition. I have looked at previous posts and answers regarding this and everything is too complex. I will mark the easiest to understand response that still has the key information as the answer.

推荐答案

的InitializeComponent 是当你创建/修改表单的窗体设计器会自动为您编写的方法。

InitializeComponent is a method automatically written for you by the Form Designer when you create/change your forms.

每一个表单文件(例如Form1.cs中)有一个设计文件(例如Form1.designer.cs)包含InitializeComponent方法,通用的的覆盖Form.Dispose ,然后都喜欢按钮,文本框和标签的用户界面对象的声明。

Every Forms file (e.g. Form1.cs) has a designer file (e.g. Form1.designer.cs) that contains the InitializeComponent method, the override of the generic Form.Dispose, and the declaration of all of your User Interface objects like buttons, textboxes and labels.

的InitializeComponent 方式包含使用的属性网格的初始化与你(程序员)提供的值的用户界面对象的代码窗体设计器。此外,您将在这里找到,链接控制和形成事件,你写的响应用户的操作具体的事件处理程序所需的管道。

The InitializeComponent method contains the code that initialize the user interface objects with the values provided by you (the programmer) using the Property Grid of the form designer. Also, you will find here, the plumbing required to link the controls and form events to the specific event handlers you write to respond to the user actions.

中包含的代码Form1.cs和在Form1.designer.cs文件是同一类感谢的部分类,可以让你的代码的两个或多个部件在一起,就像一个单一的代码块。

The code contained in Form1.cs and the Form1.Designer.cs files is part of the same class thanks to the concept of partial classes that could keep two or more parts of your code together like a single block of code.

当然,由于任何用户界面所需修改的机会高,它确实是一个很好的建议为不要尝试手动修改此法,同时,有时我觉得将代码添加到Dispose方法是有用的。

Of course, due to the high chance of modifications required by any user interface, it is a really good advice to not try to modify manually this method, while, sometime I find useful to add code to the Dispose method.

这篇关于在InitializeComponent()的非常简单的定义;方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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