码迷,mamicode.com
首页 > Windows程序 > 详细

无边框窗体

时间:2016-07-06 21:42:12      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

一、无边框窗体

1.创建无边框窗体

将窗体FormBorderStyle属性设为None

技术分享

2.设置一个关闭按钮功能

(1)添加一个pictureBox,将背景改为关闭图像

(2)设置鼠标移入,移出,点击等事件

        /// <summary>
        /// 鼠标移入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.BackgroundImage = Image.FromFile("G:\\WinForm\\2016-7-4\\Buttons\\btn_close_highlight.png");
        }
        /// <summary>
        /// 鼠标移出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.BackgroundImage = Image.FromFile("G:\\WinForm\\2016-7-4\\Buttons\\btn_close_disable.png");
        }
        /// <summary>
        /// 鼠标按下
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox1.BackgroundImage = Image.FromFile("G:\\WinForm\\2016-7-4\\Buttons\\btn_close_down.png");
        }
        /// <summary>
        /// 鼠标点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否退出?", "退出",MessageBoxButtons.OKCancel,MessageBoxIcon.Information) == DialogResult.OK)
            {
                this.Close();
            }
        }

技术分享技术分享技术分享

技术分享

3.窗体移动

        //无边框移动
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;
        [DllImport("user32")]
        private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
        private const int WM_SETREDRAW = 0xB;

        private void Form4_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.WindowState == FormWindowState.Normal)
            {
                ReleaseCapture();
                SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
            }
        }

 

无边框窗体

标签:

原文地址:http://www.cnblogs.com/bosamvs/p/5648118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!