inputbox的输入字符能否控制,比如让输入的字都是*号,像密码的那种?

解决方案 »

  1.   

    自己写个类,模拟实现inputbox也可以啊!
      

  2.   

    可以修改单元文件并重新编译DUC就OK啊,
      

  3.   

    你是说直接改inputbox的源代码?
      

  4.   

    unit mydialogs;interfaceuses 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;
    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 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.