


 
 
 
 
 
 
 |
Delphi2010 ボタン(Button) 2010/08/20 |
前頁で[Standard]内の「Memo」(メモ)について書きましたので次に、同じく[Standard]内の「Button」(ボタン)について見てみます。ボタンは Delphi6 にもあります。その前に、テスト2画面も煩雑になってきましたので、テスト3(003フォルダ)を作って作業をします。
ボタンは [はい] [いいえ] の選択や [OK] での確認・決定、[開始] [終了] [閉じる]など、いろいろな事を行う際に ぽちっとな〜と押したりするものですね。それでは配置してみます。1つ目なので Nameプロパティは「Button1」となり、Captionプロパティは「Button1」となります。
ボタン上の文字は Captionプロパティで指定します。
<フォームデザイナ>上のボタンをダブルクリックするか<オブジェクトインスペクタ>のイベント頁のOnClick欄をダブルクリックして、ボタンをクリックした時の処理(イベントハンドラ)を記述します。<コードエディタ>でメッセージ表示を行うようにします。
procedure TForm1.Button1Click(Sender: TObject);
begin
MessageDlg('ボタンを押しました!', mtInformation,
[mbOk], 0, mbOk);
end; |
保存・コンパイル(再構築)・実行します。ボタンをクリックすると・・・
<オブジェクトインスペクタ>を見ていきます。
まずは Styleプロパティでしょうか。ボタン形状を選択できます。
bsPushButton |  | 従来型のボタン デフォルト状態 |
bsSplitButton |

 |
ドロップダウンメニューのあるボタン Vista/7で可能
ポップアップメニューを用意し、DropDownMenuプロパティでそれを指定すると、そのメニューを表示・選択出来る |
bsCommandLink |

 |
コマンドリンクスタイルのボタン Vista/7で可能
CommandLinkHintプロパティでキャプションの下に説明文字を表示させることが出来る |
Windows98/Me/2000/Xp/Vista/7用のプログラムを作ることと、WindowsVista/7専用のプログラムを作ることとを明確に切り分ける、って考えた方がいいのかもしれません。これだけ外観と動きが違うと・・・。
次に、ModalResultプロパティですが、これはメイン画面というよりは、ShowModalでダイアログ画面を表示して何かを選択する等の画面を作成する場合、例えば[OK]ボタンのModalResultプロパティをmrOkに、[キャンセル]ボタンのModalResultプロパティをmrCancelにしておけば、そのFormのModalResult プロパティにどのボタンを押して閉じたのかが分かるようにする、というものです。私自身はこれまで FormのPublic宣言部に「OKflag:Boolean;」等と書いておいて、その変数を設定・参照して[OK]したのか[Cancel]したのかを判定していましたが、そういう事をしなくてもいいって事ですね。
そして Images関連のプロパティ、これはイメージリストですね。
このようなボタンは BitBltボタンやSpeedButtonって感じでしたが、普通のボタンでも出来るようになったのですね。いろいろ拡張されているようです。ついでに、ボタンの色を指定できるようになっていると少し嬉しかったんですが、それは無いようです。
|
|
バッチファイル
BASIC
C言語のお勉強
拡張子な話
DOSプログラム
Delphi
>Delphi入門編
>Delphi2010
▲2010/08/19
2010/08/20
▼2010/08/21
シェアウェア
Script!World
データベース
|