The Brushes Sample shows you how to use four different brushes in several shapes. Below is a code snippet showing how to use hatched and gradient brushes.
GDI+ features a TextureBrush that lets you draw repeating patterns. You can specify any bitmap to be drawn repeatedly. In this example we create bitmaps using code and attach them to a TextureBrush.
The Graphics.RenderingOrigin property lets you specify a Point structure that represents the dither origin for 8-bits-per-pixel and 16-bits-per-pixel dithering and is also used to set the origin for hatch brushes.
The following example shows how to use RenderingOrigin:
namespace Scrollable1
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
/// /// Summary description for ScrollableControl1./// publicclassScrollableControl1 : System.Windows.Forms.ScrollableControl
{
privatevoidInitializeComponent(){
}
publicScrollableControl1(){
InitializeComponent ();
this.AutoScrollMinSize = new Size(500, 500);
}
protectedoverridevoidOnPaint(PaintEventArgs pe){
pe.Graphics.RenderingOrigin = AutoScrollPosition;
HatchBrush br = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Blue, Color.White);
pe.Graphics.FillRectangle(br, ClientRectangle /*or pe.ClipRectangle*/);
br.Dispose();
}
}
}