Export (0) Print
Expand All
3 out of 6 rated this helpful - Rate this topic

Form.Opacity Property

Gets or sets the opacity level of the form.

[Visual Basic]
Public Property Opacity As Double
[C#]
public double Opacity {get; set;}
[C++]
public: __property double get_Opacity();
public: __property void set_Opacity(double);
[JScript]
public function get Opacity() : double;
public function set Opacity(double);

Property Value

The level of opacity for the form. The default is 1.00.

Remarks

This property enables you to specify a level of transparency for the form and its controls. This property differs from transparency provided by the TransparencyKey which only makes a form and its controls completely transparent if they are the same color as the value specified in the TransparencyKey property. When this property is set to a value less than 100% (1.00), the entire form, including borders, is made more transparent. Setting this property to a value of 0% (0.00) makes the form completely invisible. You can use this property to provide different levels of transparency or to provide effects such as phasing a form in or out of view. For example, you can phase a form into view by setting the Opacity property to a value of 0% (0.00) and gradually increasing the value until it reaches 100% (1.00).

Windows 2000, Windows Server 2003 family Platform Note:  This property has no effect on platforms that cannot display layered windows.

Example

[Visual Basic, C#, C++] The following example demonstrates how to create a form that is displayed with an opacity level of 75 percent. The example code creates a new form that is positioned in the center of the screen with an Opacity property set to change the opacity level of the form. The example code also sets the Size property to provide a larger sized form than the default size of the form. This example assumes that the method defined in this example is called from another form in an event handler or other method.

[Visual Basic] 
Private Sub CreateMyOpaqueForm()
   ' Create a new form.
   Dim form2 As New Form()
   ' Set the text displayed in the caption.
   form2.Text = "My Form"
   ' Set the opacity to 75%.
   form2.Opacity = 0.75
   ' Size the form to be 300 pixels in height and width.
   form2.Size = New Size(300, 300)
   ' Display the form in the center of the screen.
   form2.StartPosition = FormStartPosition.CenterScreen

   ' Display the form as a modal dialog box.
   form2.ShowDialog()
End Sub

[C#] 
private void CreateMyOpaqueForm()
{
   // Create a new form.
   Form form2 = new Form();
   // Set the text displayed in the caption.
   form2.Text = "My Form";
   // Set the opacity to 75%.
   form2.Opacity = .75;
   // Size the form to be 300 pixels in height and width.
   form2.Size = new Size(300,300);
   // Display the form in the center of the screen.
   form2.StartPosition = FormStartPosition.CenterScreen;

   // Display the form as a modal dialog box.
   form2.ShowDialog();
}

[C++] 
private:
   void CreateMyOpaqueForm()
   {
      // Create a new form.
      Form* form2 = new Form();
      // Set the text displayed in the caption.
      form2->Text = S"My Form";
      // Set the opacity to 75%.
      form2->Opacity = .75;
      // Size the form to be 300 pixels in height and width.
      form2->Size = System::Drawing::Size(300,300);
      // Display the form in the center of the screen.
      form2->StartPosition = FormStartPosition::CenterScreen;

      // Display the form as a modal dialog box.
      form2->ShowDialog();
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Form Class | Form Members | System.Windows.Forms Namespace | TransparencyKey

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.