Color.Transparent Property
.NET Framework 3.0
Gets a system-defined color.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Assembly: System.Drawing (in system.drawing.dll)
The following code example demonstrates how to use the Transparent property. This example is designed to be used with Windows Forms. Paste the code into a form that contains two buttons named Button1 and Button2. Call the UseTransparentProperty method in the form's constructor.
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
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: