.net framework3.0 引入了WPF,WCF,WWF,CardSpace等新的类库,本身还是需要CLR2.0
对WinForm想必学员都已经很清楚,就是从System.Forms空间下的Application的静态方法Run传递一个Form类对象实例就OK了.关键代码如下:
System.Windows.Forms.Application.Run(new System.Windows.Forms.Form())
编译方法:
csc /t:winexe SimpleWinForm.cs
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*--===------------------------------------------===---
* 最简单的WinForm:
* Application.Run( new System.Windows.Forms.Form())
* --===------------------------------------------===---*/
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
using System.Windows.Forms;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace Chapter01
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public class SimpleWinform : Form
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public SimpleWinform()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.Text = "手工创建的WinForm窗体.";
this.Opacity = .5;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public class RunSimpleWinform
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public static void Main_SimpleWinform()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//Application.Run(new Form());
Application.Run(new SimpleWinform());
}
}
}
WPF窗体必须引用4个类库:PresentationCore, PresentationFramework, System, WindowsBase,然后会发现Forms命名空间下面多了Windows类,这就是WPF的窗体对象. 编译完成后可以用reflector对生成的执行文件反编译,参照reference就可以知道引用了那些dll库。
编译方法:
csc /t:winexe SimpleWPFWindow.cs /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" /R:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll" /R:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll"
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*--===------------------------------------------===---
* WPF实现示例:
* 引入类库:PresentationCore, PresentationFramework,WindowsBase,
* --===------------------------------------------===---*/
using System;
using System.Windows;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace Chapter01
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
class WPF_Window
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
[STAThread]
public static void Main()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
System.Windows.Window window = new Window();
window.Title = "手工实现的WPF窗体";
window.Show();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Application application = new Application();
application.Run();
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
WPF桌面窗体和WinForm对比:
WPF通过在
System.Windows命名空间下面加新类Window和Application分别实现窗体和程序线程;
System.Windows.Window window = new Window();
System.Windows.Application application = new Application();
而Winform通过.net2.0提供的
System.Windows.Forms命名空间下的Form类实现.
System.Windows.Forms.Application.Run(new System.Windows.Forms.Form());