TextureBrush Class
.NET Framework 2.0
Each property of the TextureBrush class is a Brush object that uses an image to fill the interior of a shape. This class cannot be inherited.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Assembly: System.Drawing (in system.drawing.dll)
The following code example demonstrates how to obtain a new bitmap using the FromFile method. It also demonstrates a TextureBrush.
This example is designed to be used with Windows Forms. Create a form containing a button named Button2. Paste the code into the form and associate the Button2_Click method with the button's Click event.
Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click Try Dim image1 As Bitmap = _ CType(Image.FromFile("C:\Documents and Settings\" _ & "All Users\Documents\My Music\music.bmp", True), Bitmap) Dim texture As New TextureBrush(image1) texture.WrapMode = Drawing2D.WrapMode.Tile Dim formGraphics As Graphics = Me.CreateGraphics() formGraphics.FillEllipse(texture, _ New RectangleF(90.0F, 110.0F, 100, 100)) formGraphics.Dispose() Catch ex As System.IO.FileNotFoundException MessageBox.Show("There was an error opening the bitmap." _ & "Please check the path.") End Try End Sub
private void button2_Click(Object sender, System.EventArgs e)
{
try {
Bitmap image1 = ((Bitmap)(Image.FromFile(
"C:\\Documents and Settings\\"
+ "All Users\\Documents\\My Music\\music.bmp", true)));
TextureBrush texture = new TextureBrush(image1);
texture.set_WrapMode(System.Drawing.Drawing2D.WrapMode.Tile);
Graphics formGraphics = this.CreateGraphics();
formGraphics.FillEllipse(texture, new RectangleF(90, 110, 100,100));
formGraphics.Dispose();
}
catch (System.IO.FileNotFoundException exp) {
MessageBox.Show(("There was an error opening the bitmap."
+ "Please check the path."));
}
} //button2_Click
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: