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

【转】Winform 去掉 最大化 最小化 关闭按钮(不是关闭按钮变灰)终极解决办法

时间:2016-07-23 16:30:04      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:

不墨迹, 如图 :

技术分享
网上 看了,好多 给的 答案 乱码七糟,都是扯淡,于是乎 自己 写,代码如下:
窗体的大小暂时设置为:(598, 362) 涂红的数据根据你的窗体大小改动


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;

namespace WinDemo
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Button 按钮重绘事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Paint(object sender, PaintEventArgs e)
        {
            GraphicsPath myPath = new GraphicsPath();
            Rectangle rect = new Rectangle(0,0,574,362);//后面2个数据调整窗体大小
            myPath.AddRectangle(rect);
            this.Region = new Region(myPath);
        }

        [DllImport("user32.dll")]
        static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

        [DllImport("User32.dll")]

        private static extern IntPtr GetWindowDC(IntPtr hWnd);

        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            const int WM_NCPAINT = 0x85;
            base.WndProc(ref m);

            if (m.Msg == WM_NCPAINT)
            {

                IntPtr hdc = GetWindowDC(m.HWnd);
                if ((int)hdc != 0)
                {
                    Graphics g = Graphics.FromHdc(hdc);
                    Pen pen1 = new Pen(Color.FromArgb(64,64,64));
                    Pen pen2 = new Pen(Color.FromArgb(128, 128, 128));
                    Pen pen3 = new Pen(Color.FromArgb(212, 208, 200));
                    g.DrawLine(pen1, 573, 0, 573, 360);//最外边
                    g.DrawLine(pen2, 572, 1, 572, 359);//最外边第二条白色
                    g.DrawLine(pen3, 571, 2, 571, 359);
                    g.DrawLine(pen3, 571, 2, 571, 359);
                    g.Flush();
                    ReleaseDC(m.HWnd, hdc);
                }
            }
        }
        private void Form5_MouseCaptureChanged(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen1 = new Pen(Color.FromArgb(64, 64, 64));
            Pen pen2 = new Pen(Color.FromArgb(128, 128, 128));
            Pen pen3 = new Pen(Color.FromArgb(212, 208, 200));
            g.DrawLine(pen1, 573, 0, 573, 360);//最外边
            g.DrawLine(pen2, 572, 1, 572, 359);//最外边第二条白色
            g.DrawLine(pen3, 571, 2, 571, 359);
            g.DrawLine(pen3, 571, 2, 571, 359);
            g.Flush();
        }
}
}




Source Code : http://download.csdn.net/detail/zydcomputers/4055787

【转】Winform 去掉 最大化 最小化 关闭按钮(不是关闭按钮变灰)终极解决办法

标签:

原文地址:http://www.cnblogs.com/xuan52rock/p/5698753.html

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