关于inputbox的一个小问题

computerstarveling 2003-10-20 10:51:19
inputbox的输入字符能否控制,比如让输入的字都是*号,像密码的那种?
...全文
88 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wujunwei 2003-10-21
  • 打赏
  • 举报
回复
自己写个类,模拟实现inputbox也可以啊!
fj218 2003-10-21
  • 打赏
  • 举报
回复
unit mydialogs;

interface

uses Windows,
//SysUtils,
Graphics,
Controls,
Forms, Shlobj,
StdCtrls;
function MyInputQuery(const ACaption, APrompt: string;var Value: string): Boolean;
function MyInputBox(const ACaption, APrompt, ADefault: string): string;


implementation

function 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 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);
passwordchar:='*'; // 就是这里
MaxLength := 20; //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;

function MyInputBox(const ACaption, APrompt, ADefault: string): string;
begin
Result := ADefault;
MyInputQuery(ACaption, APrompt, Result);
end;


end.
computerstarveling 2003-10-21
  • 打赏
  • 举报
回复
你是说直接改inputbox的源代码?
fhuibo 2003-10-21
  • 打赏
  • 举报
回复
maskedit
  • 打赏
  • 举报
回复
可以修改单元文件并重新编译DUC就OK啊,
computerstarveling 2003-10-21
  • 打赏
  • 举报
回复
有这个类的代码吗,给小弟研究研究.
computerstarveling 2003-10-20
  • 打赏
  • 举报
回复
用Edit还要加个窗口,不好.
luhualing 2003-10-20
  • 打赏
  • 举报
回复
为何不用Edit控件呢?

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧