forms - 将表格移动到右下角

标签 forms delphi delphi-xe7

一段时间以来,我一直在努力将运行时创建的表单移动到主表单的右下角。

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    procedure Button1Click(Sender: TObject);
//    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
//    procedure WindowPosChanging(var Msg : TMessage); message WM_WINDOWPOSCHANGING;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  F1 : TForm;
begin
   F1 := TForm.Create(nil);
   F1.Height := 300;
   F1.Width :=300;
   F1.Position := poDesktopCenter;
   F1.Name := 'asdf';
   F1.Left:=ClientOrigin.X;//+ ActiveControl.Left+ ClientOrigin.X;
   F1.Top:=ClientOrigin.Y;//+ClientOrigin.Y;
   F1.Show;
end;

//procedure TForm1.FormClick(Sender: TObject);
//var
//  pt : TPoint;
//begin
//   pt := mOUse.CursorPos;
//   lABEL3.Caption := IntToStr(pt.X);
//   label4.Caption := IntToStr(pt.Y);
//end;
//
//procedure TForm1.WindowPosChanging(var Msg: TMessage);
//begin
//    Label1.Caption :=  IntToStr(ClientOrigin.X);
//    Label2.Caption :=  IntToStr(ClientOrigin.Y);
//end;

end.

所以我们有这个例子。

F1.Position := poDesktopCenter;

如果您想将窗体置于桌面中心,此命令非常有效,但我想要实现的是将 F1 窗体定位在主窗体的底角。我不知道该怎么做。

像这样的东西 enter image description here

最佳答案

在以下所有情况下,使用

F1.Position := poDesigned;

F1 parent = Form1,在 Form1 边框内右下

F1.Parent := self;
F1.Left := self.ClientWidth - F1.Width;
F1.Top  := self.ClientHeight - F1.Height;

Self 是可选的,但它清楚地表明您引用了 Form1 的属性,您在其中执行代码。

F1 父级未分配,右下角有重叠边框

F1.Left := Left + Width - F1.Width;
F1.Top  := Top + Height - F1.Height;

F1 父级未分配,右下角在 Form1 的边界内

F1.Left := ClientOrigin.X + ClientWidth - F1.Width;
F1.Top  := ClientOrigin.Y + ClientHeight - F1.Height;

感谢 Sertac 提醒我 ClientOrigin

关于forms - 将表格移动到右下角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28762879/

相关文章:

c# - 我有一个 c sharp dll。我怎样才能使它在其他语言(例如 PHP 或 Delphi)中可用?

mysql - 德尔福、dbExpress 和 UTF8

sql-server - 当 DataTypeCompatility 打开时,如何将 12/30/1899 参数化为 SQL Server native 客户端?

delphi - 为什么当 btn 为 NIL 时我可以访问 btn.Caption?

delphi - 如何在不使用 IDE 的情况下编译 Delphi 应用程序?

iis-7 - ASP Classic 应用程序中的 Multipart/form-data 和 UTF-8

javascript - 表单输入时移除占位符后显示div

javascript - python mechanize - 提交自定义表单

delphi - 漏洞 : Cannot edit hints/warnings in BPL project options

jquery - 通过 Ajax 提交的多个 Jquery 日期选择器和表单