0

I had defined the border style to none to making a Borderless Form, with an override method to customized title bar.

But when I put a panel control in design mode, it will cover my customized title bar, or put a statusStrip control under the Form, also cover outside border line which were customization by the form.

enter image description here

I set panel's top/left/width value to limit prevent exceeding the window, but it is not a good solution, because I also want to using Control.Dock Property to let it 'docked to its parent control'.

I had found another approach here: WPF borderless window resize with inner-margins ,but it can't.

I want to drag a new control then fixed green area enter image description here

Can I define 'margins' like CSS BOX, let the all new controls add to Form1 in design mode, then automatic to range of restrictions?

This my code to build a borderless form:

----
Test.cs
----

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace TestForm
{
    public partial class Test : Form
    {
        protected override void WndProc(ref Message m)
        {   
        ....
            base.WndProc(ref m);
        }
        private const int cGrip = 20;      // Grip size
        private const int cCaption = 35;   // Caption bar height;

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x84)
            {
                Point pos = new Point(m.LParam.ToInt32());
                pos = this.PointToClient(pos);
                if (pos.Y < cCaption)
                {
                    m.Result = (IntPtr)2;
                    return;
                }
                if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip)
                {
                    m.Result = (IntPtr)17;
                    return;
                }
            }
            base.WndProc(ref m);
        }
        protected override void OnLoad(EventArgs e)
        {
            FormBorderStyle = FormBorderStyle.None;
            base.OnLoad(e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle borderRectangle = this.ClientRectangle;
            borderRectangle.Inflate(0, 0);
            ControlPaint.DrawBorder3D(e.Graphics, borderRectangle, Border3DStyle.Raised);

            base.OnPaint(e);
        }

    }
}

And Form1.cs:

namespace TestForm
{
    public partial class Form1 : Test
    {
        public Form1()
        {
        //
        }
   }
}
  • .Net Framework 4.0
  • WinForms

Chinese Notes:

一旦在這個視窗放進一個 panel control,然後將其設置為「停駐於父容器中」,會造成原先的標題列效果被覆蓋; 亦或是放進一個 statusStrip control 在下方,也會造成下方版面的原本特製化視窗下方外框線被蓋住。

是否可以讓這個 From 可以直接在設計階段時,就可以讓所有被拖拉進來的 Controls 都限縮在一個特定範圍內?

kkasp
  • 113
  • 1
  • 9
  • Are you using WPF, WinForms or UWP? – MindSwipe Jan 22 '19 at 07:16
  • I am using WinForms. – kkasp Jan 22 '19 at 07:21
  • Wat I understand your problem is, that designer does not "show" this borderless form. If your issue is just about designing it, I would suggest to make a UserControl, design everything there, and then put only this UC into you borderless window. – Malior Jan 22 '19 at 07:21
  • It seems you are looking for this: [UserControl with header and content - Allow dropping controls in content panel and Prevent dropping controls in header at design time](https://stackoverflow.com/a/50772584/3110834) – Reza Aghaei Jan 22 '19 at 09:10
  • You could use a Panel as a *makeshift* Titlebar. This will also allow to get rid of the WndProc override you have now. Btw, you have two of them. You could also opt for [DWM composition](https://learn.microsoft.com/en-us/windows/desktop/dwm/composition-ovw). – Jimi Jan 22 '19 at 16:45

0 Answers0