{A}
简介
我是一个年轻的德国学生,所以请原谅我糟糕的英语... ...今年,我安装了微软新的Office套件,并使用它从第一分钟,我真正喜欢漂亮的GUI,尤其是好看的状态栏。因为我从来没有看到一个关于如何做一个类似的背景(我看到一些教程绘制单个项目),我决定借此机会,写一个自己的教程。它是如何工作
起初,我添加了双缓冲的功能,使用此代码(初学者):Public Sub New()
Me.DoubleBuffered = True
InitializeComponent()
End Sub
要绘制背景,你需要On_Paint事件。唯一要做的就是绘制顶部和两个LinearGradients(工期1:2)的边界。如果SizingGrip应涂(Me.SizingGrip = TRUE),你应该这样做。要得到的边界绘制SizingGrip,您可以使用此代码:{C}使用代码
您可以简单地添加控制工具箱和使用它像一个quot; regularquot; StatusStrip。
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace NiceStatus
{
public class NiceStatusStrip : StatusStrip
{
protected override void OnPaint(PaintEventArgs e)
{
Graphics grfx = e.Graphics;
using(Pen p = new Pen(Color.FromArgb(86, 125, 176)))
{
grfx.DrawLine(p, 0, 0, Width - 1, 0);
}
grfx.DrawLine(Pens.White, 0, 1, Width - 1, 1);
int height = (Height - 1) / 3;
Rectangle lrect = new Rectangle(0, 2, Width, height);
using(Brush br = new LinearGradientBrush(lrect, Color.FromArgb(215, 230, 249), Color.FromArgb(199, 220, 248), LinearGradientMode.Vertical))
{
grfx.FillRectangle(br, lrect);
}
lrect.Y = lrect.Y + height;
lrect.Height = Height - lrect.Y;
using(Brush br = new LinearGradientBrush(lrect, Color.FromArgb(179, 208, 245), Color.FromArgb(205, 224, 247), LinearGradientMode.Vertical))
{
grfx.FillRectangle(br, lrect);
}
if(SizingGrip)
{
Rectangle sgb = SizeGripBounds;
using(Brush fbr = new SolidBrush(Color.FromArgb(69, 93, 128)))
{
using(Brush bbr = new SolidBrush(Color.FromArgb(177, 201, 232)))
{
//right-top
grfx.FillRectangle(bbr, new Rectangle(sgb.X + sgb.Width - 3, sgb.Height + sgb.Y - 13, 2, 2));
grfx.FillRectangle(fbr, new Rectangle(sgb.X + sgb.Width - 4, sgb.Y + sgb.Height - 14, 2, 2));
//right-middle
grfx.FillRectangle(bbr, new Rectangle(sgb.X + sgb.Width - 3, sgb.Height + sgb.Y - 9, 2, 2));
grfx.FillRectangle(fbr, new Rectangle(sgb.X + sgb.Width - 4, sgb.Y + sgb.Height - 10, 2, 2));
//right-bottom
grfx.FillRectangle(bbr, new Rectangle(sgb.X + sgb.Width - 3, sgb.Height + sgb.Y - 5, 2, 2));
grfx.FillRectangle(fbr, new Rectangle(sgb.X + sgb.Width - 4, sgb.Y + sgb.Height - 6, 2, 2));
//middle-center
grfx.FillRectangle(bbr, new Rectangle(sgb.X + sgb.Width - 7, sgb.Height + sgb.Y - 9, 2, 2));
grfx.FillRectangle(fbr, new Rectangle(sgb.X + sgb.Width - 8, sgb.Y + sgb.Height - 10, 2, 2));
//middle-bottom
grfx.FillRectangle(bbr, new Rectangle(sgb.X + sgb.Width - 7, sgb.Height + sgb.Y - 5, 2, 2));
grfx.FillRectangle(fbr, new Rectangle(sgb.X + sgb.Width - 8, sgb.Y + sgb.Height - 6, 2, 2));
//bottom left
grfx.FillRectangle(bbr, new Rectangle(sgb.X + sgb.Width - 11, sgb.Height + sgb.Y - 5, 2, 2));
grfx.FillRectangle(fbr, new Rectangle(sgb.X + sgb.Width - 12, sgb.Y + sgb.Height - 6, 2, 2));
}
}
}
base.OnPaint(e);
}
}
}