Archive for the ‘Windows Forms’ Category

  1. Hello, Windows Forms(IronPython) World!

    Posted on 6月 8th, 2012 by cx20

    Windows Forms(IronPython)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は IronPython における Windows フォーム の例となっている。

    ソースコード

    import clr
    clr.AddReference("System.Windows.Forms")
    clr.AddReference("System.Drawing")
    from System.Windows import Forms
    from System import Drawing
     
    class HelloForm(Forms.Form):
        def __init__(self):
            self.Size = Drawing.Size( 640, 480 )
            self.Text = 'Hello, World!'
            label1 = Forms.Label()
            label1.Size = Drawing.Size( 320, 20 )
            label1.Text = 'Hello, Windows Forms(IronPython) World!'
            self.Controls.Add( label1 )
     
    if __name__ == '__main__':
        form = HelloForm()
        Forms.Application.Run(form)

    実行方法

    C:¥> ipy Hello.py

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(IronPython) World!   |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+
  2. Hello, Windows Forms(PowerShell) World!

    Posted on 6月 7th, 2012 by cx20

    Windows Forms(PowerShell)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は PowerShell における Windows フォーム の例となっている。

    ソースコード(PowerShell のみ)

    [void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    $form = New-Object Windows.Forms.Form
    $form.Size = New-Object Drawing.Size 640,480
    $form.Text = "Hello, World!"
    $label1 = New-Object Windows.Forms.Label
    $label1.Size = New-Object Drawing.Size 320, 20
    $label1.Text = "Hello, Windows Forms(PowerShell) World!"
    $form.Controls.Add( $label1 )
    $form.ShowDialog()

    なお、PowerShell 2.0 から Add-Type コマンドレットを用いることにより C# や VB.NET のコードも呼び出せるようになっている。

    ソースコード(PowerShell + C#)

    $source = @"
    using System;
    using System.Drawing;
    using System.Windows.Forms;
     
    public class HelloForm : Form
    {
        public HelloForm()
        {
            this.Size = new Size( 640, 480 );
            this.Text = "Hello, World!";
     
            Label label1 = new Label();
            label1.Size = new Size( 320, 20 );
            label1.Text = "Hello, Windows Forms(PowerShell) World!";
     
            this.Controls.Add( label1 );
        }
        [STAThread]
        public static void Main()
        {
            HelloForm form = new HelloForm();
            Application.Run(form);
        }
    }
    "@
    Add-Type -Language CSharp -TypeDefinition $source -ReferencedAssemblies ("System.Drawing", "System.Windows.Forms" )
    [HelloForm]::Main()

    ソースコード(PowerShell + VB.NET)

    $source = @"
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
     
    Public Class HelloForm
        Inherits Form
     
        Public Sub New()
            Me.Size = New Size( 640, 480 )
            Me.Text = "Hello, World!"
     
            Dim label1 As New Label
            label1.Size = New Size( 320, 20 )
            label1.Text = "Hello, Windows Forms(PowerShell) World!"
     
            Me.Controls.Add( label1 )
        End Sub
     
        <STAThread> _
        Shared Sub Main()
            Dim form As New HelloForm()
            Application.Run(form)
        End Sub
    End Class
    "@
    Add-Type -Language VisualBasic -TypeDefinition $source -ReferencedAssemblies ("System.Drawing", "System.Windows.Forms" )
    [HelloForm]::Main()

    実行方法

    C:¥> PowerShell -File Hello.ps1

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(PowerShell) World!   |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+
  3. Hello, Windows Forms(MSIL) World!

    Posted on 6月 6th, 2012 by cx20

    Windows Forms(MSIL)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は MSIL における Windows フォーム の例となっている。

    ソースコード

    //  Microsoft (R) .NET Framework IL Disassembler.  Version 4.0.30319.1
    //  Copyright (c) Microsoft Corporation. All rights reserved.
     
    // Metadata version: v4.0.30319
    .assembly extern System.Windows.Forms
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .zV.4..
      .ver 4:0:0:0
    }
    .assembly extern mscorlib
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .zV.4..
      .ver 4:0:0:0
    }
    .assembly extern System.Drawing
    {
      .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
      .ver 4:0:0:0
    }
    .assembly Hello
    {
      .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                                 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.
      .hash algorithm 0x00008004
      .ver 0:0:0:0
    }
    .module Hello.exe
    // MVID: {FF5266CD-116D-4A87-B4A5-1B94604BA0FE}
    .imagebase 0x00400000
    .file alignment 0x00000200
    .stackreserve 0x00100000
    .subsystem 0x0002       // WINDOWS_GUI
    .corflags 0x00000001    //  ILONLY
    // Image base: 0x001E0000
     
     
    // =============== CLASS MEMBERS DECLARATION ===================
     
    .class private auto ansi beforefieldinit HelloForm
           extends [System.Windows.Forms]System.Windows.Forms.Form
    {
      .method public hidebysig specialname rtspecialname 
              instance void  .ctor() cil managed
      {
        // コード サイズ       94 (0x5e)
        .maxstack  4
        .locals init (class [System.Windows.Forms]System.Windows.Forms.Label V_0)
        IL_0000:  ldarg.0
        IL_0001:  call       instance void [System.Windows.Forms]System.Windows.Forms.Form::.ctor()
        IL_0006:  nop
        IL_0007:  nop
        IL_0008:  ldarg.0
        IL_0009:  ldc.i4     0x280
        IL_000e:  ldc.i4     0x1e0
        IL_0013:  newobj     instance void [System.Drawing]System.Drawing.Size::.ctor(int32,
                                                                                      int32)
        IL_0018:  call       instance void [System.Windows.Forms]System.Windows.Forms.Form::set_Size(valuetype [System.Drawing]System.Drawing.Size)
        IL_001d:  nop
        IL_001e:  ldarg.0
        IL_001f:  ldstr      "Hello, World!"
        IL_0024:  callvirt   instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
        IL_0029:  nop
        IL_002a:  newobj     instance void [System.Windows.Forms]System.Windows.Forms.Label::.ctor()
        IL_002f:  stloc.0
        IL_0030:  ldloc.0
        IL_0031:  ldc.i4     0x140
        IL_0036:  ldc.i4.s   20
        IL_0038:  newobj     instance void [System.Drawing]System.Drawing.Size::.ctor(int32,
                                                                                      int32)
        IL_003d:  callvirt   instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Size(valuetype [System.Drawing]System.Drawing.Size)
        IL_0042:  nop
        IL_0043:  ldloc.0
        IL_0044:  ldstr      "Hello, Windows Forms(MSIL) World!"
        IL_0049:  callvirt   instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
        IL_004e:  nop
        IL_004f:  ldarg.0
        IL_0050:  call       instance class [System.Windows.Forms]System.Windows.Forms.Control/ControlCollection [System.Windows.Forms]System.Windows.Forms.Control::get_Controls()
        IL_0055:  ldloc.0
        IL_0056:  callvirt   instance void [System.Windows.Forms]System.Windows.Forms.Control/ControlCollection::Add(class [System.Windows.Forms]System.Windows.Forms.Control)
        IL_005b:  nop
        IL_005c:  nop
        IL_005d:  ret
      } // end of method HelloForm::.ctor
     
      .method private hidebysig static void  Main() cil managed
      {
        .entrypoint
        .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) 
        // コード サイズ       15 (0xf)
        .maxstack  1
        .locals init (class HelloForm V_0)
        IL_0000:  nop
        IL_0001:  newobj     instance void HelloForm::.ctor()
        IL_0006:  stloc.0
        IL_0007:  ldloc.0
        IL_0008:  call       void [System.Windows.Forms]System.Windows.Forms.Application::Run(class [System.Windows.Forms]System.Windows.Forms.Form)
        IL_000d:  nop
        IL_000e:  ret
      } // end of method HelloForm::Main
     
    } // end of class HelloForm
     
     
    // =============================================================
     
    // *********** 逆アセンブルが完了しました ***********************
    // 警告: Win32 リソース ファイル hello.res を作成しました。

    上記コードは、以下の C# の実行ファイルを ildasm.exe で逆アセンブルしたものである。

    ソースコード

    using System;
    using System.Drawing;
    using System.Windows.Forms;
     
    class HelloForm : Form
    {
        public HelloForm()
        {
            this.Size = new Size( 640, 480 );
            this.Text = "Hello, World!";
            Label label1 = new Label();
            label1.Size = new Size( 320, 20 );
            label1.Text = "Hello, Windows Forms(MSIL) World!";
            this.Controls.Add( label1 );
        }
        [STAThread]
        static void Main()
        {
            HelloForm form = new HelloForm();
            Application.Run(form);
        }
    }

    コンパイル方法

    C:¥> ilasm Hello.il
    

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(MSIL) World!         |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+
  4. Hello, Windows Forms(C++/CLI) World!

    Posted on 6月 5th, 2012 by cx20

    Windows Forms(C++/CLI)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は C++/CLI における Windows フォーム の例となっている。

    ソースコード

    #using <System.dll>
    #using <System.Drawing.dll>
    #using <System.Windows.Forms.dll>
     
    using namespace System;
    using namespace System::Drawing;
    using namespace System::Windows::Forms;
     
    public ref class HelloForm : public Form
    {
    public:
        HelloForm()
        {
            this->Size = System::Drawing::Size( 640, 480 );
            this->Text = "Hello, World!";
            Label^ label1 = gcnew Label();
            label1->Text = "Hello, Windows Forms(C++/CLI) World!";
            label1->Size = System::Drawing::Size( 320, 20 );
            this->Controls->Add( label1 );
        }
    };
     
    int main( array<System::String^>^ args )
    {
       HelloForm^ form = gcnew HelloForm();
       Application::Run(form);
     
       return 0;
    }

    コンパイル方法

    C:¥> cl Hello.cpp /clr /link /SUBSYSTEM:WINDOWS /ENTRY:main

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(C++/CLI) World!      |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+
  5. Hello, Windows Forms(JScript.NET) World!

    Posted on 6月 4th, 2012 by cx20

    Windows Forms(JScript.NET)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は JScript.NET における Windows フォーム の例となっている。

    ソースコード

    import System;
    import System.Drawing;
    import System.Windows.Forms;
    import Accessibility;
     
    main();
     
    class HelloForm extends Form
    {
        function HelloForm()
        {
            this.Size = new System.Drawing.Size( 640, 480 );
            this.Text = "Hello, World!";
            var label1 = new Label;
            label1.Size = new System.Drawing.Size( 320, 20 );
            label1.Text = "Hello, Windows Forms(JScript.NET) World!";
            this.Controls.Add( label1 );
        }
    }
     
    function main() {
        var form = new HelloForm;
        Application.Run(form);
    }

    コンパイル方法

    C:¥> jsc /target:winexe Hello.js

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(JScript.NET) World!  |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+
  6. Hello, Windows Forms(F#) World!

    Posted on 6月 3rd, 2012 by cx20

    Windows Forms(F#)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は F# における Windows フォーム の例となっている。

    ソースコード

    open System
    open System.Drawing
    open System.Windows.Forms
     
    type HelloForm() as this =
        inherit Form()
     
        do
            this.Size <- new Size( 640, 480 )
            this.Text <- "Hello, World!"
            let label1 = new Label()
            label1.Size <- new Size( 320, 20 )
            label1.Text <- "Hello, Windows Forms(F#) World!"
            do this.Controls.Add(label1)
     
    let form = new HelloForm()
    do Application.Run(form)

    コンパイル方法

    C:¥> fsc --target:winexe Hello.fs

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(F#) World!           |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+
  7. Hello, Windows Forms(VB.NET) World!

    Posted on 6月 2nd, 2012 by cx20

    Windows Forms(VB.NET)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は VB.NET における Windows フォーム の例となっている。

    ソースコード

    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
     
    Class HelloForm
        Inherits Form
     
        Public Sub New()
            Me.Size = New Size( 640, 480 )
            Me.Text = "Hello, World!"
     
            Dim label1 As New Label
            label1.Size = New Size( 320, 20 )
            label1.Text = "Hello, Windows Forms(VB.NET) World!"
     
            Me.Controls.Add( label1 )
        End Sub
     
        <STAThread> _
        Shared Sub Main()
            Dim form As New HelloForm()
            Application.Run(form)
        End Sub
    End Class

    コンパイル方法

    C:¥> vbc /target:winexe Hello.vb

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(VB.NET) World!       |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+
  8. Hello, Windows Forms(C#) World!

    Posted on 6月 1st, 2012 by cx20

    Windows Forms(C#)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は C# における Windows フォーム の例となっている。

    ソースコード

    using System;
    using System.Drawing;
    using System.Windows.Forms;
     
    class HelloForm : Form
    {
        public HelloForm()
        {
            this.Size = new Size( 640, 480 );
            this.Text = "Hello, World!";
     
            Label label1 = new Label();
            label1.Size = new Size( 320, 20 );
            label1.Text = "Hello, Windows Forms(C#) World!";
     
            this.Controls.Add( label1 );
        }
        [STAThread]
        static void Main()
        {
            HelloForm form = new HelloForm();
            Application.Run(form);
        }
    }

    コンパイル方法

    C:¥> csc /target:winexe Hello.cs

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(C#) World!           |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+