如何让窗体的位置固定在屏幕的中间?(20分)

  • 主题发起人 ltqlyy125
  • 开始时间
L

ltqlyy125

Unregistered / Unconfirmed
GUEST, unregistred user!
我设置了窗体的位置为CENTER但运行时还是可以通过标题栏移动它
怎样写代码来限制它不给移动?
 
你只要设置FORM属性的/Per..中的/center disktorp(我记不清拼写)就可以.
 
不要标题栏或者
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
protected
procedure onposchange(var msg:twmwindowposchanging);
message wm_windowposchanging;
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure tform1.onposchange(var msg:twmwindowposchanging);
begin
msg.windowpos.x:=left;
msg.WindowPos.y:=top;
msg.result:=0;
end;
end.
 
截获任务拦上的消息,如果是mousemove
就截住,其他的放过去
 
楼上的答案或者将其Align设为alclient
 
将Form1的Position属性值设为poScreenCenter即可.
 
自己写消息处理函数 WM_MOVE
每次 WM_MOVE 之后都把位置设置回去
 
呵呵,这个问题我知道。把form.borderstyle设为none,再将form1.Position设为poScreenCenter即可。
 
是一开始在中间?
是否可以进行拖动?
 
先声明
procedure WMNCHitTest(var Msg: TMessage);
message WM_NCHITTEST;
然后
procedure tform1.WMNCHitTest(var Msg: TMessage);
begin
inherited;
// 这样,移动就不可能了...
Msg.Result := HTCLIENT;
end;
再设置position:=poscreencenter
这样既在中间,又不能移动
 
>>呵呵,这个问题我知道。把form.borderstyle设为none,再将form1.Position设为poScreenCenter即可。
这个肯定正确
 
sinmonsoft的回答能满足你的要求!
 
同意sinmonsoft方法,截取WM_NCHITTEST消息进行处理,这样即能显示标题栏
又能保持在屏幕中间。
 

Similar threads

回复
0
查看
652
不得闲
S
回复
0
查看
950
SUNSTONE的Delphi笔记
S
S
回复
0
查看
771
SUNSTONE的Delphi笔记
S
顶部