All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
c#中GDI+图形图像:GDI+中的画笔使用方法

Writer: qq Article type: Programming skills(编程技巧) Time: 2014/7/11 9:16:45 Browse times: 326 Comment times: 0

c#中GDI+图形图像:GDI+中的画笔使用方法


Head photo

Go homepage
Upload pictures
Write articles

c#中GDI+图形图像:GDI+中的画笔使用方法|实例

GDI+中的画笔
闭合的形状(例如,矩形或椭圆)由轮廓和内部组成。用钢笔绘制出轮廓,并用画笔填充其内部。GDI+提供了几种填充闭合形状内部的画笔类:SolidBrush、HatchBrush、TextureBrush、LinearGradientBrush和PathGradientBrush。所有这些类都是从Brush类继承的。
1.实心画笔
使用实心画笔时,需要使用SolidBrush类,该类主要用来使用定义的单色画笔填充图形形状,如矩形、椭圆、扇形、多边形和封闭路径等。
示例
实心画笔的使用
本示例中,当程序运行时,单击【实心画笔】按钮,在窗体中绘制一个使用指定颜色填充的椭圆。示例运行结果如图1所示。

图1 实心画笔的使用
Form1窗体中,在【实心画笔】按钮的Click事件中分别声明Graphics类和SolidBrush类的两个实例对象,调用Graphics对象的FillEllipse方法在窗体中绘制一个使用指定颜色填充的椭圆。【实心画笔】按钮的Click事件代码如下:
private void button1_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
SolidBrush mySolidBrush = new SolidBrush(Color.Green);
graphics.FillEllipse(mySolidBrush, 70, 20, 100, 50);
}
完整程序代码如下:
★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace _6_09
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
SolidBrush mySolidBrush = new SolidBrush(Color.Green);
graphics.FillEllipse(mySolidBrush, 70, 20, 100, 50);
}
}
}
★ ★★★★Form1..Designer.cs窗体代码文件完整程序代码★★★★★
namespace _6_09
{
partial class Form1
{
///


/// 必需的设计器变量。
///

private System.ComponentModel.IContainer components = null;
///
/// 清理所有正在使用的资源。
///

/// 如果应释放托管资源,为 true;否则为 false。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
///

private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(82, 83);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "实心画笔";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(238, 130);
this.Controls.Add(this.button1);
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
}
}
★ ★★★★Program.cs主程序文件完整程序代码★★★★★
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace _6_09
{
static class Program
{
///
/// 应用程序的主入口点。
///

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
2.阴影画笔
使用阴影画笔时,需要使用HatchBrush类,该类位于System.Drawing.Drawing2D命名空间内,它主要使用阴影样式、前景色和背景色定义矩形画笔。




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.