在winform中隐藏或者去除c#的标题栏并实现窗体移动附代码

 设置窗体的FormBorderStyle为None

不过要自己加上一些相应的操作代码了,不然窗口是不能进行拖动关闭之类的

 #region 实现点击移动

        internal static int WM_NCHITTEST = 0x84;
        internal static IntPtr HTCLIENT = (IntPtr)0x1;
        internal static IntPtr HTCAPTION = (IntPtr)0x2;
        internal static int WM_NCLBUTTONDBLCLK = 0x00A3;
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_NCLBUTTONDBLCLK)
            {
                return;
            }
            if (m.Msg == WM_NCHITTEST)
            {
                base.WndProc(ref m);
                if (m.Result == HTCLIENT)
                {
                    m.HWnd = this.Handle;
                    m.Result = HTCAPTION;
                }
                return;
            }
            base.WndProc(ref m);
        }

        #endregion

 

你可能感兴趣的:(c#)