1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Drawing.Drawing2D;
  10. using System.Runtime.InteropServices;
  11. namespace WinDemo
  12. {
  13. public partial class Form5 : Form
  14. {
  15. public Form5()
  16. {
  17. InitializeComponent();
  18. }
  19. /// <summary>
  20. /// Button 按钮重绘事件
  21. /// </summary>
  22. /// <param name="sender"></param>
  23. /// <param name="e"></param>
  24. private void button1_Paint(object sender, PaintEventArgs e)
  25. {
  26. GraphicsPath myPath = new GraphicsPath();
  27. Rectangle rect = new Rectangle(0,0,574,362);//后面2个数据调整窗体大小
  28. myPath.AddRectangle(rect);
  29. this.Region = new Region(myPath);
  30. }
  31. [DllImport("user32.dll")]
  32. static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
  33. [DllImport("User32.dll")]
  34. private static extern IntPtr GetWindowDC(IntPtr hWnd);
  35. protected override void WndProc(ref System.Windows.Forms.Message m)
  36. {
  37. const int WM_NCPAINT = 0x85;
  38. base.WndProc(ref m);
  39. if (m.Msg == WM_NCPAINT)
  40. {
  41. IntPtr hdc = GetWindowDC(m.HWnd);
  42. if ((int)hdc != 0)
  43. {
  44. Graphics g = Graphics.FromHdc(hdc);
  45. Pen pen1 = new Pen(Color.FromArgb(64,64,64));
  46. Pen pen2 = new Pen(Color.FromArgb(128, 128, 128));
  47. Pen pen3 = new Pen(Color.FromArgb(212, 208, 200));
  48. g.DrawLine(pen1, 573, 0, 573, 360);//最外边
  49. g.DrawLine(pen2, 572, 1, 572, 359);//最外边第二条白色
  50. g.DrawLine(pen3, 571, 2, 571, 359);
  51. g.DrawLine(pen3, 571, 2, 571, 359);
  52. g.Flush();
  53. ReleaseDC(m.HWnd, hdc);
  54. }
  55. }
  56. }
  57. private void Form5_MouseCaptureChanged(object sender, EventArgs e)
  58. {
  59. Graphics g = this.CreateGraphics();
  60. Pen pen1 = new Pen(Color.FromArgb(64, 64, 64));
  61. Pen pen2 = new Pen(Color.FromArgb(128, 128, 128));
  62. Pen pen3 = new Pen(Color.FromArgb(212, 208, 200));
  63. g.DrawLine(pen1, 573, 0, 573, 360);//最外边
  64. g.DrawLine(pen2, 572, 1, 572, 359);//最外边第二条白色
  65. g.DrawLine(pen3, 571, 2, 571, 359);
  66. g.DrawLine(pen3, 571, 2, 571, 359);
  67. g.Flush();
  68. }
  69. }
  70. }

using System.Runtime.InteropServices;

[DllImport("user32.dll")]
        internal static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert);

[DllImport("user32.dll")]
        internal static extern int GetMenuItemCount(IntPtr hMenu);

[DllImport("user32.dll")]
        internal static extern int RemoveMenu(IntPtr hMenu, int uPosition, int uFlags);

///   <summary> 
        ///   窗体的关闭按钮失效 
        ///   </summary> 
        protected void CloseButtonEnable()
        {
            //   默认窗口去除关闭按钮 
            const int MF_BYPOSITION = 0x00000400;

IntPtr hWindow = this.Handle;
            IntPtr hMenu = GetSystemMenu(hWindow, false);
            int count = GetMenuItemCount(hMenu);
            RemoveMenu(hMenu, count - 1, MF_BYPOSITION);
            RemoveMenu(hMenu, count - 2, MF_BYPOSITION);
        }

private void confirm_Load(object sender, EventArgs e)
        {
            CloseButtonEnable();

}

Winform 去掉 最大化 最小化 关闭按钮(不是关闭按钮变灰)终极解决办法的更多相关文章

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

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

  2. 通过virtualbox最小化安装centos 6.3后无法上网解决办法

    通过virtualbox最小化安装centos 6.3后无法上网解决办法 1.设置virtualbox的网络连接方式,如下图使用桥接方式,桥接的网卡为宿主正在上网的网卡,现在我是通过无线来上网的,所以 ...

  3. 监听Activity进入后台(最小化),并根据时间判断是否超时,此解决办法可用于超时重登陆

    通过重写一个继承自Activity的基类中的onUserLeaveHint()方法,当用户按Home键等操作使程序进入后台时即开始计时,当用户使程序恢复为前台显示时执行onResume()方法,在其中 ...

  4. C#winform如何主窗口最大化最小化默认大小

    this.WindowState = FormWindowState.Minimized; bool b = true; private void button2_Click(object sende ...

  5. PyQt:无边框自定义标题栏及最大化最小化窗体大小调整

    环境 Python3.5.2 PyQt5 陈述 隐藏掉系统的控制栏,实现了自定义的标题控制栏,以及关闭/最大化/最小化的功能,自由调整窗体大小的功能(跟随一个大佬学的),代码内有详细注释 只要把Mai ...

  6. Qt 窗口操作函数(置顶、全屏,最大化最小化按钮设置等)

    一.窗口置顶 与 取消置顶 void MainWindow::on_windowTopButton_clicked() { if (m_flags == NULL) { m_flags = windo ...

  7. c# 窗体相关操作(最大化/最小化/关闭/标题栏)

    /// <summary> /// 窗体跟随鼠标移动的标记 /// </summary> private bool normalmoving = false; /// < ...

  8. 【转】ubuntu 12.04 LTS将关闭最大化最小化移动到右上角

    原文网址:http://www.4byte.cn/learning/114801.html ubuntu 12.04 LTS将关闭最大化最小化移动到右上角   还是按下“ALT +F2”组合键,输入g ...

  9. C#程序实现窗体的最大化/最小化

    C#程序实现窗体的最大化/最小化 http://blog.csdn.net/jiangqin115/article/details/41251215 private void button1_Clic ...

随机推荐

  1. 在Windows下使用CodeBlock使用libiconv第三方库

    在Windows下使用CodeBlock使用libiconv第三方库 1.         选择在Project->Build options下: 2.         如下图添加libicon ...

  2. Markdown 语法详解

    Markdown 学习 标题 三级标题 四级标题 最多支持六级标题 "#... + 标题名称" 字体 hello, world "** 内容 **" hello ...

  3. 半监督伪标签方法:Feature Space Regularization和Joint-Distance

    原文链接 小样本学习与智能前沿 . 在这个公众号后台回复"200706",即可获得课件电子资源. @ 目录 Abstract I. INTRODUCTION Framework. ...

  4. 再也不担心写出臃肿的Flink流处理程序啦,发现一款将Flink与Spring生态完美融合的脚手架工程-懒松鼠Flink-Boot

    目录 你可能面临如下苦恼: 接口缓存 重试机制 Bean校验 等等...... 它为流计算开发工程师解决了 有了它你的代码就像这样子: 仓库地址:懒松鼠Flink-Boot 1. 组织结构 2. 技术 ...

  5. 学习笔记(1):零基础掌握 Python 入门到实战-列表与元祖到底该用哪个?(二)...

    立即学习:https://edu.csdn.net/course/play/26676/338778?utm_source=blogtoedu 列表不能通过增加索引增加元素 可以使用list中的app ...

  6. day1(初始化项目结构)

    1.初始化项目结构  └─shiyanlou_project    │  .gitignore    │  README.en.md           # 英文    │  README.md    ...

  7. 【Docker】 CentOS7 安装 Docker 及其使用方法 ( 一 )

    系列目录: [Docker] CentOS7 安装 Docker 及其使用方法 ( 一 ) [Docker] 使用Docker 在阿里云 Centos7 部署 MySQL 和 Redis (二) [D ...

  8. Samba服务器搭建,匿名访问,用户密码访问

    环境 #服务端:centos7 客户端:centos7,windows10 配置yum源,使用光盘镜像安装Samba服务 #挂载光盘:mount  /dev/sr0  /mnt/cdrom #安装sa ...

  9. c++如何按照map的value进行排序?

    static bool cmp(pair<char, int> a , pair<char,int> b) { return a.second>b.second; //按 ...

  10. MyBatis if 标签的坑,居然被我踩到了。。。

    事件的原因是这样的,需求是按条件查数据然后给前端展示就行了,写的时候想着挺简单的,不就是使用 MyBatis 动态 SQL 去查询数据吗? 现实还是很残酷的,等我写完上完 UAT 后,前端同学说根据s ...