delphi 侧边栏隐藏窗体


本文整理自网络,侵删。

 timer1.Interval 设置为5最好


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.

相关阅读 >>

Delphi webbrowser1遍历网页中的图片

Delphi 之 对话框组件

winsock 实现telnet后门

Delphi xe7 判断android应用程序中的通信状态类型

Delphi 判断时间是否合法 -isvaliddatetime、isvaliddate、isvalidtime、isvaliddateday

Delphi 将memo转化为jpg输出

Delphi 安卓如何获取当前系统语言

Delphi andorid应用程序检查wifi有效还是无效

Delphi toolbar按钮添加图标

Delphi 屏幕拷贝程序的源代码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...