RT !
前辈!最好你就把那代码都拿出来吧!我是新手呢!还有那是不是我喜欢在哪个地方弹出来都可以吗?
小樱_花 | 浏览 680 次
问题暂时关闭
发布于2010-05-17 16:22 最佳答案
 
inputbox封装的是InputQuery函数,你可以查看InputQuery的源代码,发现在InputQuery函数里面动态创建了一个窗体,你可以把InputQuery函数的源代码复制出来,自己修改成可控制位置的就行了 

unit inputboxExs;

interface

uses Windows, Graphics, Forms, StdCtrls, Consts, Dialogs, Controls;

function InputQueryEx(const ACaption, APrompt: string;
var Value: string; X, Y: Integer): Boolean;

function InputBoxEx(const ACaption, APrompt, ADefault: string; X, Y: Integer): 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 InputQueryEx(const ACaption, APrompt: string;
var Value: string; X, Y: Integer): 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);
Left := X;
Top := Y;
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;
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 InputBoxEx(const ACaption, APrompt, ADefault: string; X, Y: Integer): string;
begin
Result := ADefault;
InputQueryEx(ACaption, APrompt, Result, X, Y);
end;

以上是源代码,在Delphi源代码基础上稍微修改了下,我单独写在了一个文件中,使用时需要引用我这个单元文件,下面是调用示例:
uses inputboxExs;

procedure TForm1.Button2Click(Sender: TObject);
var str1, str2: string;
begin
// 参数中的X,Y,就是你想设置的位置
str1 := InputBoxEx('注意', '输入数字', str2, 100, 10);
ShowMessage(str1);
end;
 

kcxnvbdbd 

采纳率:55% 擅长: 其他编程语言 C#/.NET

其他回答

呵呵,这个有意思,我学了一下,哈哈
changjeff  发布于2010-05-16 12:32
评论 
0

为您推荐:

 
登录 

还没有百度账号?
立即注册

 

知道日报

全部文章
运动后腿酸是因为乳酸吗?
 
更多的百度推广结果>>
关于百度为您推荐更多优质结果,放心搜索,有V有保障.