Freigeben über


TextureBrush-Klasse

Jede Eigenschaft der TextureBrush-Klasse ist ein Brush-Objekt, das das Innere einer Form mit einem Bild ausfüllt. Diese Klasse kann nicht vererbt werden.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

'Declaration
Public NotInheritable Class TextureBrush
    Inherits Brush
'Usage
Dim instance As TextureBrush
public sealed class TextureBrush : Brush
public ref class TextureBrush sealed : public Brush
public final class TextureBrush extends Brush
public final class TextureBrush extends Brush

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mithilfe der FromFile-Methode eine neue Bitmap abgerufen wird. Außerdem wird ein TextureBrush veranschaulicht.

Dieses Beispiel ist für die Verwendung mit Windows Forms vorgesehen. Erstellen Sie ein Formular, das eine Schaltfläche mit dem Namen Button2 enthält. Fügen Sie den Code in das Formular ein, und ordnen Sie dem Click-Ereignis der Schaltfläche die Button2_Click-Methode zu.

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(System.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.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
        Graphics formGraphics = this.CreateGraphics();
        formGraphics.FillEllipse(texture, 
            new RectangleF(90.0F, 110.0F, 100, 100));
        formGraphics.Dispose();

    }
    catch(System.IO.FileNotFoundException)
    {
        MessageBox.Show("There was an error opening the bitmap." +
            "Please check the path.");
    }

}
private:
   void Button2_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      try
      {
         Bitmap^ image1 = dynamic_cast<Bitmap^>(Image::FromFile( "C:\\Documents and Settings\\"
         "All Users\\Documents\\My Music\\music.bmp", true ));
         TextureBrush^ texture = gcnew TextureBrush( image1 );
         texture->WrapMode = System::Drawing::Drawing2D::WrapMode::Tile;
         Graphics^ formGraphics = this->CreateGraphics();
         formGraphics->FillEllipse( texture, RectangleF(90.0F,110.0F,100,100) );
         delete formGraphics;
      }
      catch ( System::IO::FileNotFoundException^ ) 
      {
         MessageBox::Show( "There was an error opening the bitmap."
         "Please check the path." );
      }
   }
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

Vererbungshierarchie

System.Object
   System.MarshalByRefObject
     System.Drawing.Brush
      System.Drawing.TextureBrush

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

TextureBrush-Member
System.Drawing-Namespace