当前位置:编程学习 > Delphi >>

delphi界面怎么设置像QQ一样自动隐藏

用delphi开发的软件 生成的EXE文件

怎么像QQ界面那样

拖到windows窗口边沿的时候自动隐藏

鼠标放上去的时候又显示出来?

追问:

什么控件

答案:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls,Math, StdCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
procedure Timer1Timer(Sender: TObject);
private
FAnchors: TAnchors;
procedure WMMOVING(var Msg: TMessage);message WM_MOVING;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.WMMOVING(var Msg: TMessage);
begin
inherited;
with PRect(Msg.LParam)^ do
begin
Left := Min(Max(0, Left), Screen.Width - Width);
Top := Min(Max(0, Top), Screen.Height - Height);
Right := Min(Max(Width, Right), Screen.Width);
Bottom := Min(Max(Height, Bottom), Screen.Height);
FAnchors := [];
if Left = 0 then Include(FAnchors, akLeft);
if Right = Screen.Width then
Include(FAnchors, akRight);
if Top = 0 then Include(FAnchors, akTop);
if Bottom = Screen.Height then
Include(FAnchors, akBottom);
Timer1.Enabled := FAnchors <> [];
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
const
cOffset = 2;
begin
if WindowFromPoint(Mouse.CursorPos) = Handle then
begin
if akLeft in FAnchors then Left := 0;
if akTop in FAnchors then Top := 0;
if akRight in FAnchors then
Left := Screen.Width - Width;
if akBottom in FAnchors then
Top := Screen.Height - Height;
end else
begin
if akLeft in FAnchors then Left := -Width + cOffset;
if akTop in FAnchors then Top := -Height + cOffset;
if akRight in FAnchors then
Left := Screen.Width - cOffset;
if akBottom in FAnchors then
Top := Screen.Height - cOffset;
end;
end;

end.

有一个控件,可以直接使用就能达到自动隐藏的效果了!

在form_move事件中判断一下窗体的坐标,如果Y值小于等于0,则把窗体的高度缩小(不能缩到0,否则就没办法重新显示出来了)

在form_mousemove事件中判断鼠标的位置,在范围内就把窗体的高度恢复为正常值,否则再次把他缩小.

上一个:怎样在delphi的click中加自定义参数
下一个:计算时间我们会有误差?delphi

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,