J jake502010 Unregistered / Unconfirmed GUEST, unregistred user! 2005-04-02 #4 好像不行吧!(不要你想硬改也行重新构建吧!) 还是自己加个窗体吧。 用现成的总是有一些不足!
J jfyes Unregistered / Unconfirmed GUEST, unregistred user! 2005-04-02 #6 { Input dialog } function InputQuery(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); Position := poScreenCenter; Prompt := TLabel.Create(Form); with Prompt do begin Parent := Form; Caption := APrompt; Left := MulDiv(8, DialogUnits.X, 4); Top := MulDiv(8, DialogUnits.Y, 8); Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4); WordWrap := True; end; Edit := TEdit.Create(Form); with Edit do begin Parent := Form; Passwordchar := '*' // 这里修改 Left := Prompt.Left; Top := Prompt.Top + Prompt.Height + 5; Width := MulDiv(164, DialogUnits.X, 4); MaxLength := 255; Text := Value; SelectAll; end; ButtonTop := Edit.Top + Edit.Height + 15; 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), Edit.Top + Edit.Height + 15, ButtonWidth, ButtonHeight); Form.ClientHeight := Top + Height + 13 end; if ShowModal = mrOk then begin Value := Edit.Text; Result := True; end; finally Form.Free; end; end; function InputBox(const ACaption, APrompt, ADefault: string): string; begin Result := ADefault; InputQuery(ACaption, APrompt, Result); end; 放在自己的单元里调用就是
{ Input dialog } function InputQuery(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); Position := poScreenCenter; Prompt := TLabel.Create(Form); with Prompt do begin Parent := Form; Caption := APrompt; Left := MulDiv(8, DialogUnits.X, 4); Top := MulDiv(8, DialogUnits.Y, 8); Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4); WordWrap := True; end; Edit := TEdit.Create(Form); with Edit do begin Parent := Form; Passwordchar := '*' // 这里修改 Left := Prompt.Left; Top := Prompt.Top + Prompt.Height + 5; Width := MulDiv(164, DialogUnits.X, 4); MaxLength := 255; Text := Value; SelectAll; end; ButtonTop := Edit.Top + Edit.Height + 15; 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), Edit.Top + Edit.Height + 15, ButtonWidth, ButtonHeight); Form.ClientHeight := Top + Height + 13 end; if ShowModal = mrOk then begin Value := Edit.Text; Result := True; end; finally Form.Free; end; end; function InputBox(const ACaption, APrompt, ADefault: string): string; begin Result := ADefault; InputQuery(ACaption, APrompt, Result); end; 放在自己的单元里调用就是
S stlont Unregistered / Unconfirmed GUEST, unregistred user! 2005-04-02 #7 只要用最基本的edit控件, 就有passwordchar属性, 设置为*就可以了 InputQuery不提供此功能
J jfyes Unregistered / Unconfirmed GUEST, unregistred user! 2005-04-02 #9 把上面两个function 复制到你的单元里面就可以了。 function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean; function InputBox(const ACaption, APrompt, ADefault: string): string; function Tform.function InputBox(const ACaption, APrompt, ADefault: string): string; function Tform.InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;
把上面两个function 复制到你的单元里面就可以了。 function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean; function InputBox(const ACaption, APrompt, ADefault: string): string; function Tform.function InputBox(const ACaption, APrompt, ADefault: string): string; function Tform.InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;