▼.Net Compact Framework 2.0メモ▼
はじめてのWindows Mobileアプリケーションの作成
「Hello World!」という文字列を表示するだけのWindows Mobileアプリケーションを作成する。
プロジェクトの作成
- Visual Studioのメニュー「ファイル→新規作成→プロジェクト」を選択。
- ウィンドウ左のツリー「Visual C#→スマートデバイス→Windows Mobile 6 Professional」を選択。
- ウィンドウ右のテンプレート「Device Application」を選択。
- プロジェクト名とソリューション名に「HelloWorld」、場所に任意の場所を指定しOKボタンを押す。
デザインの編集
ソリューションエクスプローラのForm1.csを右クリックし、「名前の変更」を選択してForm1.csをHelloForm.csと名前変更。
以下のように編集。
HelloForm
プロパティ 値 Text HelloWorld MinimizeBox false FormFactor Windows Mobile 6 Professional VGA
ソースコードの編集
ソリューションエクスプローラのHelloForm.csを右クリックし、「コードの表示」を選択してソースコードを表示
以下のように編集。
HelloForm.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace HelloWorld { public partial class HelloForm : Form { //コンストラクタ public HelloForm() { InitializeComponent(); } //描画イベント protected override void OnPaint(PaintEventArgs pea) { Graphics g =pea.Graphics; Font font =new Font("MS ゴシック",24,FontStyle.Regular); SolidBrush brush=new SolidBrush(Color.Black); g.DrawString("Hello World!",font,brush,10,10); } } }
実行
Visual Studioのメニュー「デバッグ⇒デバッグ開始」を選択。
アプリケーションを配置するエミュレータ(JPNではじまるのが日本語スキン)を選択してOKボタンを押す。
横画面にするにはエミュレータスキンのカレンダーボタンを押す。