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常规

C#界面美化小技巧_第1张图片

4.配色

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

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

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

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

C#界面美化小技巧_第2张图片

6.给Button美化

C#界面美化小技巧_第3张图片

 

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;

你可能感兴趣的:(c#,开发语言)