C#实现无边框winfrom界面

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u014715882/article/details/83215003

winfrom界面其实也可以扁平化,让外观提升一个level,整体为360风格。先上图:
在这里插入图片描述

首先在界面属性中,将FormBorderStyle设置为None,然后界面变为正常的Panel。此时需要添加顶栏拖动、最小化和关闭按钮。


        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;

        #region 窗体操作

        /// <summary>
        /// 窗体拖动
        /// </summary>
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }

        /// <summary>
        /// 绘制边框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bodyPanel_Paint(object sender, PaintEventArgs e)
        {
            Pen p = new Pen(Color.FromArgb(109, 155, 241));
            e.Graphics.DrawRectangle(p, 0, 0, this.bodyPanel.Width - 1, this.bodyPanel.Height - 1);
        }

        /// <summary>
        /// 最小化窗体
        /// </summary>
        private void minPictureBox_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        /// <summary>
        /// 关闭窗体
        /// </summary>
        private void closePictureBox_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void minPictureBox_MouseEnter(object sender, EventArgs e)
        {
            this.minPictureBox.Image = global::GSOperateMgrTool.Properties.Resources.最小化鼠标经过;
        }
        private void minPictureBox_MouseLeave(object sender, EventArgs e)
        {
            this.minPictureBox.Image = global::GSOperateMgrTool.Properties.Resources.最小化;
        }
        private void closePictureBox_MouseEnter(object sender, EventArgs e)
        {
            this.closePictureBox.Image = global::GSOperateMgrTool.Properties.Resources.关闭鼠标经过;
        }
        private void closePictureBox_MouseLeave(object sender, EventArgs e)
        {
            this.closePictureBox.Image = global::GSOperateMgrTool.Properties.Resources.关闭;
        }
        /// <summary>
        ///设置最小化和关闭图片tip提示
        /// </summary>
        private void SetToolTip()
        {
            //定义ToolTip对象
            ToolTip toolTip = new ToolTip();
            toolTip.AutoPopDelay = 5000;
            toolTip.InitialDelay = 100;
            toolTip.ReshowDelay = 500;
            toolTip.ShowAlways = true;
            toolTip.SetToolTip(this.minPictureBox,"最小化");
            toolTip.SetToolTip(this.closePictureBox, "关闭");
        }
展开阅读全文

没有更多推荐了,返回首页