开发者

What does this code means? [closed]

开发者 https://www.devze.com 2023-01-30 06:15 出处:网络
开发者_如何学C It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
开发者_如何学C It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.
namespace myApplication    {
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
}

What is partial class Form1 : Form

and what is InitializeComponents();

and why it is used Form1 : Form instead of only Form1


InitializeComponents(); is a function for initializing the values of the form. Please right click on it and click on Showdefinition to see its contents. It is used to assign values to labels, textbox, Buttons etc in your form.

public partial class Form1 : Form By using partial it is possible to write the definition of same class in two different source file in the same namespace.It will be treated as same during compilation.You can find a class with same name Form1 in your project which is created automatically.

Form1 is the name of the Form and : is used to inherit the properties of base class . Here Form represents System.Windows.Forms.Form. We are inheriting to access the properties and methods of base class.


Let's look at partial class Form1 : Form - obviously this is declaring a class called Form1. The : Form part means that it inherits from the base class Form.

The base Form class provides lots of functionality needed by all forms - including InitializeComponents() (more on which below).

The partial keyword means that this class is only partly defined in this source file, and the compiler must look elsewhere for the remainder of the definition (in this case it will be some automatically generated code which defines amongst others all the controls you placed on your form in the designer).

InitializeComponents() is a required call in all subclasses of Form and it instructs all the components on the form to initialise, position, and display themselves as appropriate.


  1. Class declaration
  2. Method call
  3. Inheritance

But asking questions like this is no good.

0

精彩评论

暂无评论...
验证码 换一张
取 消