【问题标题】:Borderless form with Aero Snap creates white border on top带有 Aero Snap 的无边框表格在顶部创建白色边框
【发布时间】:2019-12-29 23:26:38
【问题描述】:

我正在创建一个将FormBorderStyle 设置为None 的表单。

我正在使用以下方法来启用 Aero Snapping:

protected override CreateParams CreateParams
{
  get
  {
    CreateParams cp = base.CreateParams;
    {
      cp.Style |= 0x20000 | 0x80000 | 0x40000; //WS_MINIMIZEBOX | WS_SYSMENU | WS_SIZEBOX;
    }
     return cp;
  }
}

这很好用,只是它会产生两个问题。

  1. 现在我的表单顶部有一个无法删除的白色边框。
  2. 当我将表单捕捉到屏幕顶部时,它会填满整个屏幕,覆盖任务栏。

我绝对是这方面的初学者,因此非常感谢任何帮助。

【问题讨论】:

    标签: c# aero borderless


    【解决方案1】:

    对于第二点,有一个解决方案。但我对第一个有同样的问题。这是解决方案: MaximizedBounds = Screen.FromHandle(Handle).WorkingArea;

    【讨论】:

      【解决方案2】:

      这是更好的解决方案,修复了可调整大小、无边框、顶部白条、areo 边缘捕捉、全屏大小、...:

      type
        TBorderlessForm = class(TForm)
          CustomTitleBar: TPanel;
          procedure CustomTitleBarMouseDown(Sender: TObject; Button: TMouseButton;
            Shift: TShiftState; X, Y: Integer);
          procedure CustomTitleBarDblClick(Sender: TObject);
      
        private
          function IsBorderless: Boolean;
          function GetBorderSpace: Integer;
      
          procedure WM_NCCalcSize(var Msg: TWMNCCalcSize); message WM_NCCALCSIZE;
          procedure WM_NCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
      
        protected
          procedure Paint; override;
          procedure Resize; override;
      
        public
        end;
      
      ...
      
      function TBorderlessForm.IsBorderless: Boolean;
      begin
        Result := BorderStyle in [bsNone, bsToolWindow, bsSizeToolWin];
      end;
      
      function TBorderlessForm.GetBorderSpace: Integer;
      begin
        case BorderStyle of
          bsSingle:
            Result :=
              GetSystemMetrics(SM_CYFIXEDFRAME);
          bsDialog, bsToolWindow:
            Result :=
              GetSystemMetrics(SM_CYDLGFRAME);
          bsSizeable, bsSizeToolWin:
            Result :=
              GetSystemMetrics(SM_CYSIZEFRAME) +
              GetSystemMetrics(SM_CXPADDEDBORDER);
          else
            Result := 0;
        end;
      end;
      
      { CUSTOM METHODS }
      
      procedure TBorderlessForm.Paint;
      begin
        inherited;
        if (WindowState = wsNormal) and (not IsBorderless) then
          begin
            Canvas.Pen.Color := clBlack;
            Canvas.MoveTo(0, 0);
            Canvas.LineTo(Width, 0);
          end;
      end;
      
      procedure TBorderlessForm.Resize;
      begin
        inherited;
        if (WindowState = wsNormal) and (not IsBorderless) then
          Padding.Top := 1
        else
          Padding.Top := 0;
      end;
      
      { MESSAGES }
      
      procedure TBorderlessForm.WM_NCCalcSize(var Msg: TWMNCCalcSize);
      var
        CaptionBarHeight: Integer;
      begin
        inherited;
        if BorderStyle = bsNone then exit;
      
        CaptionBarHeight := GetSystemMetrics(SM_CYCAPTION);
        if WindowState = wsNormal then
          Inc(CaptionBarHeight, GetBorderSpace);
      
        Dec(Msg.CalcSize_Params.rgrc[0].Top, CaptionBarHeight);
      end;
      
      procedure TBorderlessForm.WM_NCHitTest(var Msg: TWMNCHitTest);
      var
        ResizeSpace: Integer;
      begin
        inherited;
        ResizeSpace := GetBorderSpace;
      
        if
          (WindowState = wsNormal) and
          (BorderStyle in [bsSizeable, bsSizeToolWin]) and
          (Msg.YPos - BoundsRect.Top <= ResizeSpace)
        then
          begin
            if Msg.XPos - BoundsRect.Left <= 2 * ResizeSpace then
              Msg.Result := HTTOPLEFT
            else if BoundsRect.Right - Msg.XPos <= 2 * ResizeSpace then
              Msg.Result := HTTOPRIGHT
            else
              Msg.Result := HTTOP;
          end;
      end;
      
      procedure TBorderlessForm.CustomTitleBarDblClick(Sender: TObject);
      begin
        if WindowState = wsNormal then
          WindowState := wsMaximized
        else
          WindowState := wsNormal;
      end;
      
      procedure TBorderlessForm.CustomTitleBarMouseDown(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
      begin
        ReleaseCapture;
        Perform(WM_SYSCOMMAND, $F012, 0);
      end;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-05
        • 2023-02-21
        • 2011-02-08
        • 2011-03-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多