输入框:

answer:=Inputbox('a','b','c');

效果很好,但是我正在寻找一个蒙面的,例如一个密码框,您只能看到小星星而不是打字字符。

有帮助吗?

解决方案

您可以将Windows消息发送到由由 InputBox, ,这将标记为密码输入的编辑控件。以下代码取自 http://www.swissdelphicenter.ch/en/showcode.php?id=1208:

const
   InputBoxMessage = WM_USER + 200;

type
   TForm1 = class(TForm)
     Button1: TButton;
     procedure Button1Click(Sender: TObject);
   private
     procedure InputBoxSetPasswordChar(var Msg: TMessage); message InputBoxMessage;
   public
   end;

var
   Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.InputBoxSetPasswordChar(var Msg: TMessage);
var
   hInputForm, hEdit, hButton: HWND;
begin
   hInputForm := Screen.Forms[0].Handle;
   if (hInputForm <> 0) then
   begin
     hEdit := FindWindowEx(hInputForm, 0, 'TEdit', nil);
     {
       // Change button text:
       hButton := FindWindowEx(hInputForm, 0, 'TButton', nil);
       SendMessage(hButton, WM_SETTEXT, 0, Integer(PChar('Cancel')));
     }
     SendMessage(hEdit, EM_SETPASSWORDCHAR, Ord('*'), 0);
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   InputString: string;
begin
   PostMessage(Handle, InputBoxMessage, 0, 0);
   InputString := InputBox('Input Box', 'Please Enter a Password', '');
end;

其他提示

在xe2中, InputBox()InputQuery() 已更新为本地支持掩盖 TEdit 输入,尽管该功能尚未记录。如果是 APrompt 参数设置为任何值 #32 然后 TEdit.PasswordChar 将设置为 *, ,例如:

answer := InputBox('a', #31'b', 'c');

输入框调用对话框中的输入函数,该函数动态创建表单。您始终可以复制此功能,并更改TEDIT的密码Chare属性。

我不认为Delphi开箱即用。也许您可以在 http://www.torry.net/ 或网中的其他地方。否则,请自己写一个 - 不应该那么难。 :-)如果您拥有“足够大”的Delphi版本,您甚至可以查看源代码。

Uli。

您可以使用InputQuery而不是输入框。设置真实参数后,将掩盖密码字段。

InputQuery('Authenticate', 'Password:',TRUE, value);     

这里一些资源; http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/inputquery.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top