using
System;// 基础核心命名空间
using
System.Collections.Generic;
//包含了ArrayList、BitArray、Hashtable、Stack、StringCollection 和 StringTable 类
using
System.ComponentModel;
using
System.Data;//数据库访问控制
using
System.Drawing;//绘图类
using
System.Text;//文本类
using
System.Windows.Forms; //大量窗体和控件
namespace
WindowsApplication1 //当前操作的命名控件是WindowsApplication1
{
public partial class Form011 : Form //
从 System.Windows.Forms.Form 中派生
{
public Form011()
{
InitializeComponent();//注意该方法在下面的介绍
}
}
}
|
理解
Using
语句
Using
语句通常出现在一个
.cs
文件中的头部,用于定义引用系统命名空间,具体的操作方法和属性等被定义在该系统的命名控件之中,比如如果不写
using
System.Drawing,则无法在后期开发之中进行图形图像方面的设计开发。
另一方面,用户可以定义用户自定义类在一个用户自定义的命名空间下,这样在头部通过
Using
语句声明该
用户自定义的命名空间,从而获取该命名空间下的具体类以及该类的属性和方法,达到对于系统软件分层开发的目的。
|
//位于.cs文件之中的InitializeComponent()方法
public Form011()
{
InitializeComponent();
}
|
namespace
WindowsApplication1
{
partial class Form011
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(70, 43);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 54);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 12);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// Form011
//
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F , 12F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(458, 326);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "Form011";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form011";
this.ResumeLayout(false);
this.PerFormLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
}
}
|
请更改
InitializeComponent()
方法中的相关属性参数,观察界面的显示是否有变化。
|
using
System;
using
System.Collections.Generic;
using
System.Windows.Forms;
namespace
WindowsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form011());//此处黑体字部分决定那个窗体文件首先被执行。
}
}
}
|
本文出自 “熊猫写程序” 博客,转载请与作者联系!