Freigeben über


Color.Transparent-Eigenschaft

Ruft eine systemdefinierte Farbe ab.

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

Syntax

'Declaration
Public Shared ReadOnly Property Transparent As Color
'Usage
Dim value As Color

value = Color.Transparent
public static Color Transparent { get; }
public:
static property Color Transparent {
    Color get ();
}
/** @property */
public static Color get_Transparent ()
public static function get Transparent () : Color

Eigenschaftenwert

Eine Color, die eine systemdefinierte Farbe darstellt.

Beispiel

Im folgenden Codebeispiel wird die Verwendung der Transparent-Eigenschaft veranschaulicht. Dieses Beispiel ist für die Verwendung mit Windows Forms vorgesehen. Fügen Sie den Code in ein Formular ein, das zwei Schaltflächen mit den Namen Button1 und Button2 enthält. Rufen Sie die UseTransparentProperty-Methode im Konstruktor des Formulars auf.

Private Sub UseTransparentProperty()

    ' Set up the PictureBox to display the entire image, and
    ' to cover the entire client area.
    PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    PictureBox1.Dock = DockStyle.Fill

    Try
        ' Set the Image property of the PictureBox to an image retrieved
        ' from the file system.
        PictureBox1.Image = _
            Image.FromFile("C:\Documents and Settings\All Users\" _
            & "Documents\My Pictures\Sample Pictures\sunset.jpg")

        ' Set the Parent property of Button1 and Button2 to the 
        ' PictureBox.
        Button1.Parent = PictureBox1
        Button2.Parent = PictureBox1

        ' Set the Color property of both buttons to transparent. 
        ' With this setting, the buttons assume the color of their
        ' parent.
        Button1.BackColor = Color.Transparent
        Button2.BackColor = Color.Transparent

    Catch ex As System.IO.FileNotFoundException
        MessageBox.Show("There was an error." _
        & "Make sure the image file path is valid.")
    End Try


End Sub
private void UseTransparentProperty()
{

    // Set up the PictureBox to display the entire image, and
    // to cover the entire client area.
    PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    PictureBox1.Dock = DockStyle.Fill;

    try
    {
        // Set the Image property of the PictureBox to an image retrieved
        // from the file system.
        PictureBox1.Image = 
            Image.FromFile("C:\\Documents and Settings\\All Users\\" +
            "Documents\\My Pictures\\Sample Pictures\\sunset.jpg");

        // Set the Parent property of Button1 and Button2 to the 
        // PictureBox.
        Button1.Parent = PictureBox1;
        Button2.Parent = PictureBox1;

        // Set the Color property of both buttons to transparent. 
        // With this setting the buttons assume the color of their
        // parent.
        Button1.BackColor = Color.Transparent;
        Button2.BackColor = Color.Transparent;

    }
    catch(System.IO.FileNotFoundException)
    {
        MessageBox.Show("There was an error." +
            "Make sure the image file path is valid.");
    }


}
private:
   void UseTransparentProperty()
   {
      // Set up the PictureBox to display the entire image, and
      // to cover the entire client area.
      PictureBox1->SizeMode = PictureBoxSizeMode::StretchImage;
      PictureBox1->Dock = DockStyle::Fill;
      try
      {
         // Set the Image property of the PictureBox to an image retrieved
         // from the file system.
         PictureBox1->Image = Image::FromFile( "C:\\Documents and Settings\\All Users\\"
         "Documents\\My Pictures\\Sample Pictures\\sunset.jpg" );

         // Set the Parent property of Button1 and Button2 to the 
         // PictureBox.
         Button1->Parent = PictureBox1;
         Button2->Parent = PictureBox1;

         // Set the Color property of both buttons to transparent. 
         // With this setting the buttons assume the color of their
         // parent.
         Button1->BackColor = Color::Transparent;
         Button2->BackColor = Color::Transparent;
      }
      catch ( System::IO::FileNotFoundException^ ) 
      {
         MessageBox::Show( "There was an error."
         "Make sure the image file path is valid." );
      }
   }
private void UseTransparentProperty()
{
    // Set up the PictureBox to display the entire image, and
    // to cover the entire client area.
    pictureBox1.set_SizeMode(PictureBoxSizeMode.StretchImage);
    pictureBox1.set_Dock(DockStyle.Fill);
    try {
        // Set the Image property of the PictureBox to an image retrieved
        // from the file system.
        pictureBox1.set_Image(Image.FromFile((
            "C:\\Documents and Settings\\All Users\\" 
            + "Documents\\My Pictures\\Sample Pictures\\sunset.jpg")));

        // Set the Parent property of button1 and button2 to the 
        // PictureBox.
        button1.set_Parent(pictureBox1);
        button2.set_Parent(pictureBox1);

        // Set the Color property of both buttons to transparent. 
        // With this setting the buttons assume the color of their
        // parent.
        button1.set_BackColor(Color.get_Transparent());
        button2.set_BackColor(Color.get_Transparent());
    }
    catch (System.IO.FileNotFoundException exp) {
        MessageBox.Show(("There was an error." 
            + "Make sure the image file path is valid."));
    }
} //UseTransparentProperty

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, 1.0

Siehe auch

Referenz

Color-Struktur
Color-Member
System.Drawing-Namespace