zoukankan      html  css  js  c++  java
  • WPF最简单的窗体实现,对比WinForm

    .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

    /*--===------------------------------------------===---
     * 最简单的WinForm: 
     *      Application.Run( new System.Windows.Forms.Form())
     * --===------------------------------------------===---
    */


    using System.Windows.Forms;

    namespace Chapter01
    {
        
    public class SimpleWinform : Form
        
    {
            
    public SimpleWinform()
            
    {
                
    this.Text = "手工创建的WinForm窗体.";
                
    this.Opacity = .5;
            }

        }


        
    public class RunSimpleWinform
        
    {
            
    public static void Main_SimpleWinform()
            
    {
                
    //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"

    /*--===------------------------------------------===---
     * WPF实现示例:
     * 引入类库:PresentationCore, PresentationFramework,WindowsBase,
     * --===------------------------------------------===---
    */

    using System;
    using System.Windows;

    namespace Chapter01
    {
        
    class WPF_Window
        
    {
            [STAThread]
            
    public static void Main()
            
    {
                System.Windows.Window window 
    = new Window();
                window.Title 
    = "手工实现的WPF窗体";
                window.Show();

                Application application 
    = new Application();
                application.Run();
            }

        }

    }

    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());
  • 相关阅读:
    GNU make manual 翻译(九十九)
    GNU make manual 翻译( 九十五)
    Shell的 for 循环小例子
    makefile中对目录遍历的小例子
    GNU make manual 翻译(九十三)
    GNU make manual 翻译( 一百)
    GNU make manual 翻译( 九十七)
    GNU make manual 翻译( 九十八)
    mapserver4.8.3 的readme.win32的中文翻译文件
    遥控器编程
  • 原文地址:https://www.cnblogs.com/flaaash/p/1049359.html
Copyright © 2011-2022 走看看