按鈕Button的代碼簡寫 |
答題得分者是:change.jian
|
zxy666666
中階會員 發表:108 回覆:150 積分:86 註冊:2005-01-14 發送簡訊給我 |
大家好!
我有三個按鈕BtUp,BtDown,BtStop
需實現如下功能:
當按BtUp時,BtUp的按鈕字體放大,而BtDown,BtStop字體縮小.
按BtDown時,BtDown的按鈕字體放大,而BtUp,BtStop字體縮小.
按BtStop時,BtDown的按鈕字體放大,而BtUp,BtDown字體縮小.
如下代碼,可以做到,但是我總覺得自己好像寫得太麻煩了一樣,
請問各位大大有沒辦法幫忙簡寫以下代碼,
比如說,怎麼樣實現代碼共用啊?請指教!感謝!!!
procedure TForm1.BtUpClick(Sender: TObject); begin with BtUp.Font do begin Size := 14; Name := '標楷體' ; Style := [fsBold] ; end; SetBtFont(BtDown); SetBtFont(BtStop); end; procedure TForm1.BtDownClick(Sender: TObject); begin with BtDown.Font do begin Size := 14; Name := '標楷體' ; Style := [fsBold] ; end; SetBtFont(BtUp); SetBtFont(BtStop); end; procedure TForm1.BtStopClick(Sender: TObject); begin with BtStop.Font do begin Size := 14; Name := '標楷體' ; Style := [fsBold] ; end; SetBtFont(BtUp); SetBtFont(BtDown); end; procedure TForm1.SetBtFont(BT:TButton); begin BT.Font.Size := 10; BT.Font.Name := '新細明體' ; BT.Font.Style := [] ; end; |
change.jian
版主 發表:29 回覆:620 積分:439 註冊:2003-06-02 發送簡訊給我 |
to zxy666666:
如下:
procedure TForm1.SetBtFont(BT: TButton; FontType: Integer); begin if FontType = 0 then begin BT.Font.Size := 10; BT.Font.Name := '新細明體' ; BT.Font.Style := [] ; end else if FontType = 1 then begin BT.Font.Size := 14; BT.Font.Name := '標楷體' ; BT.Font.Style := [fsBold] ; end; end; procedure TForm1.BtUpClick(Sender: TObject); begin SetBtFont(BtUp,0); SetBtFont(BtDown,0); SetBtFont(BtStop,0); //先把三個button的字型都縮小 SetBtFont((Sender as TButton),1); //針對被按下的那個來放大字型 end;三個button都共用這個click事件 |
zxy666666
中階會員 發表:108 回覆:150 積分:86 註冊:2005-01-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |