C#2.0初体验之WinForm篇

今天试探性的打开了66.178.223.73的VS2005,添加了个Form和几个控件,里面的代码让我有点郁闷

Form1.cs里面基本没有什么代码

#region Using directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

#endregion


namespace WindowsApplication3
{
    partial 
class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        
{

        }

    }

}


就只有构造函数,控件的事件响应函数,而且遍寻不见构造函数调用的InitializeComponent(),在这种情况下边一竟然能够通过,而且没有控件的创建代码控件也能正常显示。于是在解决方案浏览器中寻找相关代码,结果点开Form1.cs前的加号发现了Form1.Designer.cs文件,原来全藏在这里,而且这个文件的类名也是
Form1,不过前面加了修饰符Partial。

查阅相关资料才知道,Partial可将一个类的代码分配到不同的文件中,Class声明前加修饰符partial,partial 可用于 class, interface, struct 等,在 vs.net 2005 里面的 winform 和 web service wrapper 等都会使用该技术封装设计器生成的代码。

通过进一步了解发现以下几点不同:

1.  partial类的使用,分离VS自动生成的代码。
2.  引用类 代码用#Regien 包起来了

#region Using directives

using System;
using System.Collections.Generic;
using System.Windows.Forms;

#endregion


3. 程序入口改以前在Form1里面到单独的类中。

#region Using directives

using System;
using System.Collections.Generic;
using System.Windows.Forms;

#endregion


namespace WindowsApplication3
{
    
static class Program
    
{
        
/// <summary>
        
/// The main entry point for the application.
        
/// </summary>

        [STAThread]
        
static void Main()
        
{
            Application.EnableVisualStyles();
            Application.EnableRTLMirroring();
            Application.Run(
new Form1());
        }

    }

}

4.文件目录改变,将项目的属性文件放入Properties文件夹中。


其它细节发现有待以后发觉。文笔不佳请勿见笑!
原文地址:https://www.cnblogs.com/jzywh/p/222495.html