谢谢您
但是还是感觉并不是能够自动适应,因为我想着整个界面上不可能只是有一个button和一个label,如果大家摇动的话都要作相应的调整。我也试了一下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
lbl1: TLabel;
pnl1: TPanel;
btn1: TButton;
btn2: TButton;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
procedure edt1Change(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ss: Integer;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
i: Integer;
j: Integer;
begin
//i:=edt1.GetTextLen;
ShowMessage(IntToStr(btn1.Left));
ShowMessage(IntToStr(btn1.Width));
J := btn1.Left + btn1.Width;
//ShowMessage(IntToStr(lbl1.Left));
//ShowMessage(IntToStr(lbl1.Width));
{ i:=lbl1.GetTextLen;
ShowMessage(IntToStr(i)); }
end;
procedure TForm1.edt1Change(Sender: TObject);
begin
//ShowMessage(IntToStr(GetTextLen));
end;
procedure TForm1.btn2Click(Sender: TObject);
var
a, j: Integer;
// conpent : TComponent;
begin
if lbl1.Caption = 'abHiWsdfTYADFglASDF.' then Exit;
lbl1.Caption := 'abHiWsdfTYADFglASDF.';
a := lbl1.Width;
btn1.Left := btn1.Left + (a - ss);
if (edt1.Top = btn1.Top) or (edt1.Top < (btn1.Top + btn1.Height)) or ((edt1.Height - edt1.Top) < (btn1.Top + btn1.Height)) then
if edt1.Left > btn1.Left then
begin
edt1.Left := edt1.Left + (a - ss);
end;
ShowMessage(IntToStr(Form1.Width));
if Form1.Width < (btn1.Left + btn1.Width) then
begin
Form1.Width := Form1.Width + (btn1.Left + btn1.Width - Form1.Width) + 10;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ss := lbl1.Width;
end;
end.
我是定性作了一下判断并且座移动,但是还是有很多未知情况,比如,如果在窗体的边缘,窗体部能够在增大?等等问题!不过感觉这样子是不是有些太苛刻了,请您指教是不是还有其他的方法!
|