如果编写一个密码输入框(100分)

W

wangergulei

Unregistered / Unconfirmed
GUEST, unregistred user!
不需要用户设置passwordchar,直接就是显示‘*’。
是继承了tedit后,在onkeypress或者onkeyup里继承了之后写吗?能否给个例子?
多谢。
 

刘卫民

Unregistered / Unconfirmed
GUEST, unregistred user!
这个不是太难吧
从TEdit继承自己写个控件,在Create方法中直接指定PasswordChar属性为* 即可
unit PassWordEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
StdCtrls;
type
TPassWordEdit = class(TEdit)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent);
override;
published
{ Published declarations }
end;

procedure Register;
implementation
constructor TPassWordEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
PasswordChar := '*';
end;

procedure Register;
begin
RegisterComponents('Samples', [TPassWordEdit]);
end;

end.
 
X

xf_z

Unregistered / Unconfirmed
GUEST, unregistred user!
为什么我不能回复
 

无欲则刚

Unregistered / Unconfirmed
GUEST, unregistred user!
不用写控件吧,直接在onkeypress事件中把key存起来,回显一个*
 
D

djrj

Unregistered / Unconfirmed
GUEST, unregistred user!
來晚了,同意樓上的
 
A

ahhlian

Unregistered / Unconfirmed
GUEST, unregistred user!
提示性密码输入框
function GetAveCharSize(Canvas: TCanvas): TPoint;
var
I: Integer;
Buffer: array[0..51] of Char;
begin
for I := 0 to 25do
Buffer := Chr(I + Ord('A'));
for I := 0 to 25do
Buffer[I + 26] := Chr(I + Ord('a'));
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
Result.X := Result.X div 52;
end;

function PWDInputQuery(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 Formdo
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 Promptdo
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 Editdo
begin
Parent := Form;
PasswordChar:='*' ;
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;
Caption := '确定';
//SMsgDlgOK;
ModalResult := mrOk;
Default := True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,ButtonHeight);
end;
with TButton.Create(Form)do
begin
Parent := Form;
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 PWDInputBox(const ACaption, APrompt, ADefault: string): string;
begin
Result := ADefault;
PWDInputQuery(ACaption, APrompt, Result);
end;
 
K

kangshijiu

Unregistered / Unconfirmed
GUEST, unregistred user!
这样做有意义吗,简单事务复杂化.
 
0

007vivi

Unregistered / Unconfirmed
GUEST, unregistred user!
同意楼上的,简单问题不能复杂化了,那是浪费时间!
 
W

wangergulei

Unregistered / Unconfirmed
GUEST, unregistred user!
“从TEdit继承自己写个控件,在Create方法中直接指定PasswordChar属性为* 即可”
那请问,如果我要给新的控件加一个passwordstring,记录加密后的输入值,如何让
该值和输入值保持一致呢?
 
W

wangergulei

Unregistered / Unconfirmed
GUEST, unregistred user!
已解决,多谢。给分。
 
Top Bottom