C#界面美化小技巧

1.窗体设置为无边框

FormBorderStyle的属性设置为none

2.窗体无边框,可以拖拽

private Point mPoint = new Point();

        private void Download_MouseDown(object sender, MouseEventArgs e)
        {
            mPoint.X = e.X;
            mPoint.Y = e.Y;
        }

        private void Download_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point myPosittion = MousePosition;
                myPosittion.Offset(-mPoint.X, -mPoint.Y);
                Location = myPosittion;
            }
        }

3.字体

英文的话,比较推荐Arial常规

4.配色

这个网站收录了很多大品牌的配色,可以参考。

BrandColors - official brand color hex codeshttps://brandcolors.net/

5.收集一些个人比较喜欢的配色

机场航站楼时间屏幕配色就不错,可以参考

6.给Button美化

a.去掉边框

FlatStyle= flat

FlatAppearance BorderSize=0

b.Button修改成圆角

新建一个类RoundedButton: Button

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Engine
{
    public class RoundedButton : Button
    {
        protected override void OnPaint(PaintEventArgs e)
        {
            GraphicsPath path = new GraphicsPath();
            //path.AddRoundRect(this.ClientRectangle, 10); // 10是圆角的半径

            int radius = 10; // 圆角半径
            Rectangle rect = new Rectangle(0, 0, Width, Height);
            path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
            path.AddArc(rect.X + rect.Width - radius, rect.Y, radius, radius, 270, 90);
            path.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90);
            path.AddArc(rect.X, rect.Y + rect.Height - radius, radius, radius, 90, 90);
            path.CloseFigure();

            this.Region = new Region(path);
            base.OnPaint(e);
        }
    }
}

然后把Designer.cs中的button替换


 //private System.Windows.Forms.Button btnOpenCom;
private RoundedButton btnOpenCom;

//this.btnOpenCom = new System.Windows.Forms.Button();

 this.btnOpenCom = new RoundedButton();

7.用Panel加载窗体,替换tabcontrol

        public Download currentChildForm = null;

        private void OpenChildForm()
        {
            if (currentChildForm != null)
            {
                currentChildForm.Close();
                currentChildForm = new Download(mMainwin);

            }
            else
            {
                currentChildForm = new Download(mMainwin);
            }
            Download chidForm = currentChildForm;

            //currentChildForm = chidForm;
            chidForm.TopLevel = false;
            chidForm.FormBorderStyle = FormBorderStyle.None;//让窗体无边界
            chidForm.Dock = DockStyle.Fill;
            //在主窗体中添加一个Panel控件用来放置子窗体
            panel1.Controls.Add(chidForm);//将子窗体加入到Panel控件中
            panel1.Tag = chidForm;
            chidForm.BringToFront();
            chidForm.Show();//显示子窗体
        }

8.TabControl去掉(隐藏)顶部选项卡

tabControl1.SizeMode = TabSizeMode.Fixed;
tabControl1.ItemSize = new Size(0, 1);
tabControl1.Appearance=FlatButtons;

9.主界面以及控件圆角

 #region 画圆角

        [DllImport("gdi32.dll")]
        public static extern int CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3);

        [DllImport("user32.dll")]
        public static extern int SetWindowRgn(IntPtr hwnd, int hRgn, Boolean bRedraw);

        [DllImport("gdi32.dll", EntryPoint = "DeleteObject", CharSet = CharSet.Ansi)]
        public static extern int DeleteObject(int hObject);

        /// <summary>
        /// 设置窗体的圆角矩形
        /// </summary>
        /// <param name="form">须要设置的窗体</param>
        /// <param name="rgnRadius">圆角矩形的半径</param>
        public static void SetFormRoundRectRgn(Form form, int rgnRadius = 20)
        {
            int hRgn = 0;
            hRgn = CreateRoundRectRgn(0, 0, form.Width + 1, form.Height + 1, rgnRadius, rgnRadius);
            SetWindowRgn(form.Handle, hRgn, true);
            DeleteObject(hRgn);
        }
        /// <summary>
        /// 设置控件的圆角矩形
        /// </summary>
        public static void SetCtrlRoundRectRgn(IntPtr handel, int width, int height, int rgnRadius)
        {
            int hRgn = 0;
            hRgn = CreateRoundRectRgn(0, 0, width + 1, height + 1, rgnRadius, rgnRadius);
            SetWindowRgn(handel, hRgn, true);
            DeleteObject(hRgn);
        }

        /// <summary>
        /// 设置panel控件的圆角
        /// </summary>
        /// <param name="pnl"></param>
        public static void SetPanelRoundRectRgn(Panel pnl, int rgnRadius = 15)
        {
            //调用上面的第二个函数
            SetCtrlRoundRectRgn(pnl.Handle, pnl.Width, pnl.Height, rgnRadius);
        }
        #endregion

使用:

            SetFormRoundRectRgn(this, 20);

            SetPanelRoundRectRgn(panel1,15);
            
            SetCtrlRoundRectRgn(dataGridView1.Handle, dataGridView1.Width, dataGridView1.Height, 20);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值