C#2.0初体验之WinForm篇

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

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

ExpandedBlockStart.gif ContractedBlock.gif Using directives #region Using directives
InBlock.gif
InBlock.gif
using System;
InBlock.gif
using System.Collections.Generic;
InBlock.gif
using System.ComponentModel;
InBlock.gif
using System.Data;
InBlock.gif
using System.Drawing;
InBlock.gif
using System.Windows.Forms;
InBlock.gif
ExpandedBlockEnd.gif
#endregion

None.gif
None.gif
namespace  WindowsApplication3
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    partial 
class Form1 : Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public Form1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            InitializeComponent();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}


就只有构造函数,控件的事件响应函数,而且遍寻不见构造函数调用的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 包起来了

ExpandedBlockStart.gif ContractedBlock.gif Using directives #region Using directives
InBlock.gif
InBlock.gif
using System;
InBlock.gif
using System.Collections.Generic;
InBlock.gif
using System.Windows.Forms;
InBlock.gif
ExpandedBlockEnd.gif
#endregion


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

ExpandedBlockStart.gif ContractedBlock.gif Using directives #region Using directives
InBlock.gif
InBlock.gif
using System;
InBlock.gif
using System.Collections.Generic;
InBlock.gif
using System.Windows.Forms;
InBlock.gif
ExpandedBlockEnd.gif
#endregion
None.gif
None.gif
namespace  WindowsApplication3
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
static class Program
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// The main entry point for the application.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        [STAThread]
InBlock.gif        
static void Main()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Application.EnableVisualStyles();
InBlock.gif            Application.EnableRTLMirroring();
InBlock.gif            Application.Run(
new Form1());
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

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


其它细节发现有待以后发觉。文笔不佳请勿见笑!

转载于:https://www.cnblogs.com/jzywh/archive/2005/08/25/222495.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值