Archive for 6月 3rd, 2012

  1. 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!           |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+