Showmessage的字大點好嗎 |
尚未結案
|
ankin
一般會員 發表:12 回覆:7 積分:3 註冊:2002-10-17 發送簡訊給我 |
|
timhuang
尊榮會員 發表:78 回覆:1815 積分:1608 註冊:2002-07-15 發送簡訊給我 |
系統的 showmessage 沒有辦法設定字體的大小, 用個變通的方法, 動態產生一個 form 模擬 showmessage, 以下為程式碼, 其中的參數可以自行調整, 以達到最佳的視覺效果 , 其中
class="code"> procedure TForm1.Button3Click(Sender: TObject);
begin
myShowmessage('my my message: not bad', 15);
end; procedure myShowmessage(const msg: string; fontsize: integer);
var
f1: TForm;
b1: TButton;
l1: TLabel;
begin
try
f1 := TForm.Create(nil);
b1 := TButton.Create(f1);
l1 := TLabel.Create(f1); l1.Top := 15;
l1.Font.Size := fontsize;
l1.Caption := msg;
l1.Left := 20;
l1.Parent := f1; f1.Width := l1.Width 20 * 2;
f1.Height := l1.Height 120;
f1.Top := screen.Height div 2 - f1.Height div 2;
f1.Left := screen.Width div 2 - f1.Width div 2;
f1.BorderStyle := bsSingle;
f1.BorderIcons := [biSystemMenu];
f1.Caption := 'Message'; b1.Parent := f1;
b1.Top := f1.Height - b1.Height - 50;
b1.Left:= f1.Width div 2 - b1.Width div 2;
b1.Caption := 'OK';
b1.ModalResult := mrOK; f1.ShowModal;
finally
f1.Free;
end;
end;
|
nick167
中階會員 發表:86 回覆:133 積分:53 註冊:2003-02-12 發送簡訊給我 |
引言: 系統的 showmessage 沒有辦法設定字體的大小, 用個變通的方法, 動態產生一個 form 模擬 showmessage, 以下為程式碼, 其中的參數可以自行調整, 以達到最佳的視覺效果 , 其中 class="code"> procedure TForm1.Button3Click(Sender: TObject); begin myShowmessage('my my message: not bad', 15); end; procedure myShowmessage(const msg: string; fontsize: integer); var f1: TForm; b1: TButton; l1: TLabel; begin try f1 := TForm.Create(nil); b1 := TButton.Create(f1); l1 := TLabel.Create(f1); l1.Top := 15; l1.Font.Size := fontsize; l1.Caption := msg; l1.Left := 20; l1.Parent := f1; f1.Width := l1.Width 20 * 2; f1.Height := l1.Height 120; f1.Top := screen.Height div 2 - f1.Height div 2; f1.Left := screen.Width div 2 - f1.Width div 2; f1.BorderStyle := bsSingle; f1.BorderIcons := [biSystemMenu]; f1.Caption := 'Message'; b1.Parent := f1; b1.Top := f1.Height - b1.Height - 50; b1.Left:= f1.Width div 2 - b1.Width div 2; b1.Caption := 'OK'; b1.ModalResult := mrOK; f1.ShowModal; finally f1.Free; 在網站看到test後,出現message,雖不影響程式run ,如何讓它更完美,謝謝 [Warning] Unit1.pas(55): Variable 'f1' might not have been initialized end; end; |
timhuang
尊榮會員 發表:78 回覆:1815 積分:1608 註冊:2002-07-15 發送簡訊給我 |
引言: 在網站看到test後,出現message,雖不影響程式run ,如何讓它更完美,謝謝 [Warning] Unit1.pas(55): Variable 'f1' might not have been initializedHi, 將 f1 := TForm.Create(nil); 這行移至 try 的上面即可. 由於 finally 會進行 f1.Free; 的關係, 所以在 f1 的 create 要 放在 try .. finally.. end; 的外面, 所以往上移即可! procedure myShowmessage(const msg: string; fontsize: integer); var f1: TForm; b1: TButton; l1: TLabel; begin f1 := TForm.Create(nil); try b1 := TButton.Create(f1); l1 := TLabel.Create(f1); //...... |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |