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

📄 form1.cs

📁 [Visual C# 2005程序设计基础教程] 全部的源码!非常经典
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Brush
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = this.CreateGraphics();  //获取画布
            Rectangle rect = new Rectangle(10, 10, 50, 50);//定义矩形,参数为起点横纵坐标以及其长和宽

            //单色填充
            SolidBrush b1 = new SolidBrush(Color.Blue);//定义单色画刷          
            g.FillRectangle(b1, rect);              //填充这个矩形

            //输出一个字符串
            g.DrawString("字符串", new Font("宋体", 10), b1, new PointF(90, 10));

            //用图片填充
            TextureBrush b2 = new TextureBrush(Image.FromFile(@"C:\Documents and Settings\Administrator\My Documents\My Pictures\样品.jpg")); //此处修改为本地路径
            rect.Location = new Point(10, 70);//更改这个矩形的起点坐标
            rect.Width = 200;//更改这个矩形的宽来
            rect.Height = 200;//更改这个矩形的高
            g.FillRectangle(b2, rect);

            //用渐变色填充
            rect.Location = new Point(10, 290);
            LinearGradientBrush b3 = new LinearGradientBrush(rect, Color.Yellow, Color.Black, LinearGradientMode.Horizontal);
            g.FillRectangle(b3, rect);

        }
    }
}

⌨️ 快捷键说明

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