哈,才30分,少了点。不过,你又运气好,我为这个问题写个一个
myInputQuery()函数。你看看吧,如果再不明白。嘿,我就没招了。 ^-^
以下函数来自我的单元MyUnit.pas,调用该函数
无需申请dialogs.pas单元。
=============================================
//供MyInputQuery内部调用
function GetAveCharSize(Canvas: TCanvas): TPoint;
var
I: Integer;
Buffer: array[0..51] of Char;
begin
for I := 0 to 25 do Buffer := Chr(I + Ord('A'));
for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
Result.X := Result.X div 52;
end;
// 一个调整了字体的查询对话框
function MyInputQuery(const ACaption, APrompt: string;var Value: string): Boolean;
var
Form: TForm;
Prompt: TLabel;
Edit: TEdit;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: Integer;
begin
Result := False;
Form := TForm.Create(Application);
with Form do
try
Canvas.Font := Font;
DialogUnits := GetAveCharSize(Canvas);
BorderStyle := bsDialog;
Caption := ACaption;
ClientWidth := MulDiv(180, DialogUnits.X, 4);
ClientHeight := MulDiv(63, DialogUnits.Y, 8);
Position := poScreenCenter;
Prompt := TLabel.Create(Form);
with Prompt do
begin
Parent := Form;
//ADD By Aiming
Font.Name := 'Times New Roman';
Font.Size := 9;
layout := tlCenter;
//change By Aiming
AutoSize := False;
Left := MulDiv(8, DialogUnits.X, 4);
Top := 0;
Width := Muldiv(180-2*8,DialogUnits.X,4);
Height := Muldiv(18,DialogUnits.Y,8); // _EDIT.Top := MulDiv(19, DialogUnits.Y, 8);
WordWrap := True;
{
AutoSize := True;
Top := MulDiv(8, DialogUnits.Y, 8);
Left := MulDiv(8, DialogUnits.X, 4);
}
Caption := APrompt;
end;
Edit := TEdit.Create(Form);
with Edit do
begin
Parent := Form;
Left := Prompt.Left;
Top := MulDiv(19, DialogUnits.Y, 8);
Width := MulDiv(164, DialogUnits.X, 4);
MaxLength := 255;
Text := Value;
SelectAll;
end;
ButtonTop := MulDiv(41, DialogUnits.Y, 8);
ButtonWidth := MulDiv(50, DialogUnits.X, 4);
ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent := Form;
//ADD By Aiming
Font.Name := 'Times New Roman';
Font.Size := 9;
//Change by Aiming
Caption := '确认';
//Caption := SMsgDlgOK;
ModalResult := mrOk;
Default := True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent := Form;
//ADD By Aiming
Font.Name := 'Times New Roman';
Font.Size := 9;
//Change by Aiming
Caption := '放弃';
//Caption := SMsgDlgCancel;
ModalResult := mrCancel;
Cancel := True;
SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth,
ButtonHeight);
end;
if ShowModal = mrOk then
begin
Value := Edit.Text;
Result := True;
end;
finally
Form.Free;
end;
end;