8可能,Delphi帮助。 function InputBox(const ACaption, APrompt, ADefault: WideString ): WideString; overload;function InputBox(const ACaption, APrompt: WideString ; ADefault: Double; Min: Double = Low(Integer); Max: Double = High(Integer); Decimals: Integer = 1): Double; overload; function InputBox(const ACaption, APrompt: WideString; ADefault: Integer; Min: Integer = Low(Integer); Max: Integer = High(Integer); Increment: Integer = 1): Integer; overload;DescriptionCall InputBox to bring up an input dialog box ready for the user to enter a string, double, or integer in its edit box. ACaption is the caption of the dialog box. APrompt is the text that prompts the user to enter input in the edit box. ADefault is the value that appears in the edit box when the dialog box first appears. AMin is the minimum value the user can enter into the edit box. AMax is the maximum value the user can enter into the edit box. Decimals does nothing.
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
StdCtrls, Buttons;function InputQuery(const ACaption, APrompt: string;
var Value: string): Boolean;implementationfunction GetAveCharSize(Canvas: TCanvas): TPoint;
var
I: Integer;
Buffer: array[0..51] of Char;
begin
for I := 0 to 25 do Buffer[I] := 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 InputQuery(const ACaption, APrompt: string;
var Value: string): Boolean;
var
Form: TForm;
Prompt: TLabel;
Edit: TEdit;
DialogUnits: TPoint;
ButtonLeft, ButtonTop, ButtonWidth, ButtonHeight: Integer;
begin
Result := False;
Form := TForm.Create(Application);
with Form do
try
Font.Name:='宋体';
Font.Size:=9;
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;
AutoSize := True;
Left := MulDiv(8, DialogUnits.X, 4);
Top := MulDiv(8, DialogUnits.Y, 8);
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);
PasswordChar := '*';
MaxLength := 255;
Text := Value;
SelectAll;
end;
ButtonTop := MulDiv(41, DialogUnits.Y, 8);
ButtonWidth := MulDiv(50, DialogUnits.X, 4);
ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
ButtonLeft:=Edit.Left+Edit.Width-ButtonWidth;
with TButton.Create(Form) do
begin
Parent := Form;
Caption := '取消(&C)';
ModalResult := mrCancel;
Cancel := True;
SetBounds(ButtonLeft, ButtonTop, ButtonWidth,
ButtonHeight);
ButtonLeft:=ButtonLeft-ButtonWidth-5;
end;
with TButton.Create(Form) do
begin
Parent := Form;
Caption := '确定(&O)';
ModalResult := mrOk;
Default := True;
SetBounds(ButtonLeft, ButtonTop, ButtonWidth,
ButtonHeight);
end;
if ShowModal = mrOk then
begin
Value := Edit.Text;
Result := True;
end;
finally
Form.Free;
end;
end;
end.
//调用时如下:
var
S: String;
begin
if InputBoxX.InputQuery('输入', '请输入密码:', S) then
begin
//Do something...
end;
end;
找到InputQuery函数,在创建Edit的部分(with Edit do)添加一行设置属性:
PasswordChar := '*';
再运行你的程序就行了。
function InputBox(const ACaption, APrompt, ADefault: WideString ): WideString; overload;function InputBox(const ACaption, APrompt: WideString ; ADefault: Double; Min: Double = Low(Integer); Max: Double = High(Integer); Decimals: Integer = 1): Double; overload;
function InputBox(const ACaption, APrompt: WideString; ADefault: Integer; Min: Integer = Low(Integer); Max: Integer = High(Integer); Increment: Integer = 1): Integer; overload;DescriptionCall InputBox to bring up an input dialog box ready for the user to enter a string, double, or integer in its edit box. ACaption is the caption of the dialog box.
APrompt is the text that prompts the user to enter input in the edit box.
ADefault is the value that appears in the edit box when the dialog box first appears.
AMin is the minimum value the user can enter into the edit box.
AMax is the maximum value the user can enter into the edit box.
Decimals does nothing.