form 窗体增加边框_C#控件美化之路(13):美化Form窗口(上)

06879f91c5d8d62904db09ecf8b368b7.png

在开发中最重要的就是美化form窗口,在开发中,大多都是用会用自主美化的窗口开发程序。

本文只是点多,分为上中下节。分段讲解。

本文主要讲解窗口美化关键步骤。

首先美化窗体,就需要自己绘制最大化 最小化 关闭按钮。

其次就是界面样式,标题区域等

c65f006e25906403d6e8d9d71fe9b25d.png

这一步很重要,首先要将窗体属性设置为None。

其次,可以在属性中将背景颜色调整,本教程是酷黑色,用的值为 37,37,38。可以根据自己需求使用自主值。

        public WenForm()        {            InitializeComponent();            RefreshPadding();            SystemButtonAdd();            base.SetStyle(                ControlStyles.UserPaint |                ControlStyles.DoubleBuffer |                ControlStyles.OptimizedDoubleBuffer |                ControlStyles.AllPaintingInWmPaint |                ControlStyles.ResizeRedraw |                ControlStyles.SupportsTransparentBackColor, true);            base.UpdateStyles();          //获取显示器的工作区。工作区是显示器的桌面区域,不包括任务栏、停靠窗口和停靠工具栏。            this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;            this.BackColor = Color.FromArgb(37, 37, 38);            this.ForeColor = Color.White;        }

关键构造函数中相关内容,重绘用的最多的就是如上代码,基本上在重绘中使用很平凡。

        private void SystemButtonAdd()        {            buttonPointX = 0;            CloseButtonAdd();            MaxButtonAdd();            MinButtonAdd();            ConfigButtonAdd();            SkinButtonAdd();        }

接下来绘制系统按钮 ,包含最大化 最小化 关闭 按钮 ,可以根据自己需求增加按钮,例如设置按钮, 皮肤按钮等,本文教程主要绘制 5个按钮 ,代码相近。

 #region 添加关闭按钮        private void CloseButtonAdd()        {            if (this.Controls["SystemButtonClose"] is WenControl close)            {                this.Controls.Remove(close);            }            buttonPointX = buttonPointX + 46;            int x = buttonPointX;            WenControl wenControl = new WenControl()            {                BackColor = Color.Transparent,                Width = 46,                Height = 30,                Location = new Point(this.Width - x, 0),                Name = "SystemButtonClose"            };            wenControl.MouseEnter += (s, e) =>            {                wenControl.BackColor = Color.FromArgb(63, 63, 65);            };            wenControl.MouseLeave += (s, e) =>            {                wenControl.BackColor = Color.Transparent;            };            wenControl.Paint += (s, e) =>            {                Graphics g = e.Graphics;                g.SetGDIHigh();                using Pen p = new Pen(Color.White, 1);                g.DrawLine(p, 18, 11, 18 + 8, 11 + 8);                g.DrawLine(p, 18, 11 + 8, 18 + 8, 11);            };            wenControl.Click += (s, e) =>            {                this.Close();            };            this.SizeChanged += (s, e) =>            {                wenControl.Location = new Point(this.Width - x, 0);            };            this.Controls.Add(wenControl);        }        #endregion

关闭按钮

        #region 添加最大化按钮        private void MaxButtonAdd()        {            if (this.Controls["SystemButtonMax"] is WenControl max)            {                this.Controls.Remove(max);            }            if (!MaximizeBox)                return;            buttonPointX = buttonPointX + 46;            int x = buttonPointX;            WenControl wenControl = new WenControl()            {                BackColor = Color.Transparent,                Width = 46,                Height = 30,                Location = new Point(this.Width - x, 0),                Name = "SystemButtonMax"            };            wenControl.MouseEnter += (s, e) =>            {                wenControl.BackColor = Color.FromArgb(63, 63, 65);            };            wenControl.MouseLeave += (s, e) =>            {                wenControl.BackColor = Color.Transparent;            };            wenControl.Paint += (s, e) =>            {                Graphics g = e.Graphics;                g.SetGDIHigh();                using Pen p = new Pen(Color.White, 1);                if (this.WindowState == FormWindowState.Maximized)                {                    g.DrawRectangle(p, 18, 11 + 2, 6, 6);                    g.DrawRectangle(p, 18 + 2, 11, 6, 6);                }                else                {                    g.DrawRectangle(p, 18, 11, 8, 8);                }            };            wenControl.Click += (s, e) =>            {                if (WindowState == FormWindowState.Maximized)                {                    this.WindowState = FormWindowState.Normal;                }                else                {                    this.WindowState = FormWindowState.Maximized;                }            };            this.SizeChanged += (s, e) =>            {                wenControl.Location = new Point(this.Width - x, 0);            };            this.Controls.Add(wenControl);        }        #endregion

添加最大化按钮

        #region 最小化按钮        private void MinButtonAdd()        {            if (this.Controls["SystemButtonMin"] is WenControl min)            {                this.Controls.Remove(min);            }            if (!MinimizeBox)                return;            buttonPointX = buttonPointX + 46;            int x = buttonPointX;            WenControl wenControl = new WenControl()            {                BackColor = Color.Transparent,                Width = 46,                Height = 30,                Location = new Point(this.Width - x, 0),                Name = "SystemButtonMin"            };            wenControl.MouseEnter += (s, e) =>            {                wenControl.BackColor = Color.FromArgb(63, 63, 65);            };            wenControl.MouseLeave += (s, e) =>            {                wenControl.BackColor = Color.Transparent;            };            wenControl.Paint += (s, e) =>            {                Graphics g = e.Graphics;                g.SetGDIHigh();                using Pen p = new Pen(Color.White, 1);                g.DrawLine(p, 18, 15, 18 + 8, 15);            };            wenControl.Click += (s, e) =>            {                this.WindowState = FormWindowState.Minimized;            };            this.SizeChanged += (s, e) =>            {                wenControl.Location = new Point(this.Width - x, 0);            };            this.Controls.Add(wenControl);        }        #endregion

最小化按钮

        #region 设置按钮        private void ConfigButtonAdd()        {            if (this.Controls["SystemButtonConfig"] is WenControl c)            {                this.Controls.Remove(c);            }            if (!ConfigButtonBox)                return;            buttonPointX = buttonPointX + 46;            int x = buttonPointX;            WenControl wenControl = new WenControl()            {                BackColor = Color.Transparent,                Width = 46,                Height = 30,                Location = new Point(this.Width - x, 0),                Name = "SystemButtonConfig"            };            wenControl.MouseEnter += (s, e) =>            {                wenControl.BackColor = Color.FromArgb(63, 63, 65);            };            wenControl.MouseLeave += (s, e) =>            {                wenControl.BackColor = Color.Transparent;            };            wenControl.Paint += (s, e) =>            {                Graphics g = e.Graphics;                g.SetGDIHigh();                g.DrawImage(Properties.Resources.setbutton, new Rectangle(13, 5, 20, 20));            };            wenControl.Click += (s, e) =>            {                ConfigButtonClick?.Invoke(this, e);            };            this.SizeChanged += (s, e) =>            {                wenControl.Location = new Point(this.Width - x, 0);            };            this.Controls.Add(wenControl);        }        #endregion

设置按钮

        #region 皮肤按钮        private void SkinButtonAdd()        {            if (this.Controls["SystemButtonSkin"] is WenControl c)            {                this.Controls.Remove(c);            }            if (!SkinButtonBox)                return;            buttonPointX = buttonPointX + 46;            int x = buttonPointX;            WenControl wenControl = new WenControl()            {                BackColor = Color.Transparent,                Width = 46,                Height = 30,                Location = new Point(this.Width - x, 0),                Name = "SystemButtonSkin"            };            wenControl.MouseEnter += (s, e) =>            {                wenControl.BackColor = Color.FromArgb(63, 63, 65);            };            wenControl.MouseLeave += (s, e) =>            {                wenControl.BackColor = Color.Transparent;            };            wenControl.Paint += (s, e) =>            {                Graphics g = e.Graphics;                g.SetGDIHigh();                g.DrawImage(Properties.Resources.skin, new Rectangle(13, 5, 20, 20));            };            wenControl.Click += (s, e) =>            {                SkinButtonClick?.Invoke(this, e);            };            this.SizeChanged += (s, e) =>            {                wenControl.Location = new Point(this.Width - x, 0);            };            this.Controls.Add(wenControl);        }        #endregion

皮肤按钮

本文中 关闭 ,最大化 ,最小化按钮用GDI+画。也可以用图档代替。

66f89dd7e75723afcdcf5709452b230b.png
380ee4fea5415843025a8c466f652813.png

设置按钮,和皮肤按钮,在阿里图标库中下载,可以自主下载编辑。

关注文林软控,带你一起用C# 美化.NET控件。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/468939.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第四周数据结构

转载于:https://www.cnblogs.com/bgd150809329/p/6650255.html

gdb x命令_gdb基本命令

参考自:gdb基本命令(非常详细)_JIWilliams-CSDN博客_gdb命令​blog.csdn.net本文介绍使用gdb调试程序的常用命令。 GDB是GNU开源组织发布的一个强大的UNIX下的程序调试工具。如果你是在 UNIX平台下做软件,你会发现GDB这个调试工具有比VC、BCB的图形化调试…

cmds在线重定义增加列

--输出信息采用缩排或换行格式化EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, PRETTY, TRUE);--确保每个语句都带分号EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, SQLTERMINATOR, TRUE);--关闭表索引、外键等关联&…

YOLOX-PAI: An Improved YOLOX, Stronger and Faster than YOLOv6

YOLOX-PAI:一种改进的YOLOX,比YOLOv6更强更快 原文:https://arxiv.org/pdf/2208.13040.pdf 代码:https://github.com/alibaba/EasyCV 0.Abstract We develop an all-in-one computer vision toolbox named EasyCV to facilita…

Linux Shell 重定向到文件以当前时间命名

我们经常在编译的时候,需要把编译的过程日志保留下来,这时候这个命令就非常重要了。 make |tee xxx_$(date %y%m%d%H%M%S).txt

安装一直初始化_3D max 软件安装问题大全

纵使3D虐我千百遍,我待3D如初恋!大家好,我是小文。快节奏生活的今天,好不容易有点学习的热情,打开电脑学习下,没想到被简单的软件安装问题浇灭!这不是耽误了一位伟大的世界设计师诞生的节奏吗&a…

让vim显示空格,及tab字符

1、显示 TAB 键 文件中有 TAB 键的时候,你是看不见的。要把它显示出来: :set list 现在 TAB 键显示为 ^I,而 $显示在每行的结尾,以便你能找到可能会被你忽略的空白字符在哪里。 这样做的一个缺点是在有很多 TAB 的时候看起来很…

TCP/IP 协议栈 -- 编写UDP客户端注意细节

上节我们说到了TCP 客户端编写的主要细节&#xff0c; 本节我们来看一下UDP client的几种情况&#xff0c;测试代码如下&#xff1a; server&#xff1a; #include <stdio.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h>…

RuntimeError: Address already in use

问题描述&#xff1a;Pytorch用多张GPU训练时&#xff0c;会报地址已被占用的错误。其实是端口号冲突了。 因此解决方法要么kill原来的进程&#xff0c;要么修改端口号。 在代码里重新配置 torch.distributed.init_process_group()dist_init_method tcp://{master_ip}:{mast…

python读取数据流_python3+pyshark读取wireshark数据包并追踪telnet数据流

一、程序说明本程序有两个要点&#xff0c;第一个要点是读取wireshark数据包(当然也可以从网卡直接捕获改个函数就行)&#xff0c;这个使用pyshark实现。pyshark是tshark的一个python封装&#xff0c;至于tshark可以认为是命令行版的wireshark&#xff0c;随wireshark一起安装。…

Windows环境下的安装gcc

Windows具有良好的界面和丰富的工具&#xff0c;所以目前linux开发的流程是&#xff0c;windows下完成编码工作&#xff0c;linux上实现编译工作。 为了提高工作效率&#xff0c;有必要在windows环境下搭建一套gcc,gdb,make环境。 MinGW就是windows下gcc的版本。 下载地址ht…

RuntimeError: NCCL error in:XXX,unhandled system error, NCCL version 2.7.8

项目场景&#xff1a; 分布式训练中遇到这个问题&#xff0c; 问题描述 大概是没有启动并行运算&#xff1f;&#xff1f;&#xff1f;&#xff08; 解决方案&#xff1a; &#xff08;1&#xff09;首先看一下服务器GPU相关信息 进入pytorch终端&#xff08;Terminal&#x…

Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩

题目链接&#xff1a;http://codeforces.com/contest/714/problem/C C. Sonya and Queriestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday Sonya learned about long integers and invited all her friends to …

一张倾斜图片进行矫正 c++_专业性文章:10分钟矫正骨盆前倾

如今&#xff0c;骨盆前倾(又称“下交叉综合征”)非常多&#xff0c;大部分是由于以下两个原因而变得越来越突出&#xff1a;经常久坐不良的运动习惯后面我们讲到纠正骨盆前倾的四个基本步骤&#xff0c;让你快速解决&#xff0c;提高生活质量知识型和系统型的内容&#xff0c;…

vue.js源码学习分享(五)

//配置项var config {/*** Option merge strategies (used in core/util/options)//选项合并策略*/optionMergeStrategies: Object.create(null),/*** Whether to suppress warnings.//是否抑制警告*/silent: false,/*** Show production mode//生产模式 tip message on boot?…

TypeError: can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory

项目场景&#xff1a; 运行程序&#xff0c;出现报错信息 TypeError: cant convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.。 Traceback (most recent call last):File "tools/demo.py", line 97, in <module>vi…

Secure CRT 自动记录日志

配置自动log操作如下&#xff1a; 1.options ---> Global Options 2、General->Default Session->Edit Default Settings 3、Terminal->Log File 设置如图上所示 点击 日志 &#xff0c;在选项框中 Log file name中填入路径和命名参数&#xff1a; E:\Log\%Y_%M_…

java 异步调用方法_乐字节Java编程之方法、调用、重载、递归

一、概述方法是指人们在实践过程中为达到一定目的和效果所采取的办法、手段和解决方案。所谓方法&#xff0c;就是解决一类问题的代码的有序组合&#xff0c;是一个功能模块。编程语言中的方法是组合在一起来执行操作语句的集合。例如&#xff0c;System.out.println 方法&…

git clone 从GitHub上下载项目到服务器上运行+创建虚拟环境

1. 基础的Linux命令 可先进入需要放置文件的路径之下 pwd # 可看当前路径 cd …/ #返回上一层目录 cd ./xx/ #进入当前路径下的下一个文件2. GitHub项目clone到服务器上运行 # 复制GitHub页面的链接&#xff0c;在服务器后台输入git clone 命令即可 git clone https://githu…