⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdipbrushes.cs

📁 锤子大爷晓得锤子大爷晓得锤子大爷晓得锤子大爷晓得锤子大爷晓得锤子大爷晓得锤子大爷晓得
💻 CS
字号:
namespace GDIPlus.GDIPBrushes {
    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.IO;
    using System.Reflection;
    using System.Windows.Forms;

    public class BrushesSample : System.Windows.Forms.Form {
        /// <summary>
        ///    必需的设计器变量
        /// </summary>+
        private System.ComponentModel.Container components;

        private System.Drawing.Brush backgroundBrush;

        public BrushesSample() {

            //
            // Windows 窗体设计器支持所必需的
            //
            InitializeComponent();

            this.SetStyle(System.Windows.Forms.ControlStyles.Opaque, true);

            //从可执行文件的资源分支中加载要用于背景的图像
            Image backgroundImage = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("colorbars.jpg"));

            //现在创建要用于绘制背景的画笔
            backgroundBrush = new TextureBrush(backgroundImage);
        }

        protected override void OnPaint(PaintEventArgs e) {
            Graphics g = e.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            //用粗画笔填充背景
            //然后应用白色涂料
            g.FillRectangle(backgroundBrush, ClientRectangle);
            g.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.White)), ClientRectangle);

            //添加一个红色长方形和一个与之重叠的黄色长方形
            g.FillRectangle(new SolidBrush(Color.Red), 20, 20, 50, 50);
            g.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.Yellow)), 40, 40, 50, 50);

            //添加一个充满半透明阴影图案的圆圈
            HatchBrush hb = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Green, Color.FromArgb(100, Color.Yellow));
            g.FillEllipse(hb, 250, 10, 100, 100);

            //现在创建一个用渐变画笔填充的长方形
            Rectangle r = new Rectangle(300, 250, 100, 100);
            LinearGradientBrush lb = new LinearGradientBrush(r, Color.Red, Color.Yellow,LinearGradientMode.BackwardDiagonal);
            g.FillRectangle(lb, r);

            //现在添加一个用线条渐变画笔绘制的图形
            GraphicsPath path = new GraphicsPath(new Point[] {
                                                                new Point(40, 140),
                                                                new Point(275, 200),
                                                                new Point(105, 225),
                                                                new Point(190, 300),
                                                                new Point(50, 350),
                                                                new Point(20, 180),
                                                            },
                                                new byte[] {
                                                                (byte)PathPointType.Start,
                                                                (byte)PathPointType.Bezier,
                                                                (byte)PathPointType.Bezier,
                                                                (byte)PathPointType.Bezier,
                                                                (byte)PathPointType.Line,
                                                                (byte)PathPointType.Line,
                                                            }
            );

            PathGradientBrush pgb = new PathGradientBrush(path);
            pgb.SurroundColors = new Color[] {
                                                Color.Green,
                                                Color.Yellow,
                                                Color.Red,
                                                Color.Blue,
                                                Color.Orange,
                                                Color.White,
            };

            g.FillPath(pgb, path);

            //现在添加一个已被旋转的简单长方形
            g.RotateTransform(-30);
            g.FillRectangle(new SolidBrush(Color.SlateBlue), 100, 250, 75, 100);
            g.ResetTransform();
        }

        /// <summary>
        ///    清理正在使用的所有资源
        /// </summary>
        protected override void Dispose(bool disposing) {
            base.Dispose(disposing);
            components.Dispose();
        }

        /// <summary>
        ///    设计器支持所必需的方法,不要使用
        ///    代码编辑器修改此方法的内容
        /// </summary>
        private void InitializeComponent () {
            this.components = new System.ComponentModel.Container ();
            this.Text = "GDI+ 笔刷示例";
            this.Size = new System.Drawing.Size(450, 400);
        }

        /// <summary>
        /// 应用程序的主入口点
        /// </summary>
        [STAThread]
        public static void Main() {
            Application.Run(new BrushesSample());
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -