Form.Opacity Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the opacity level of the form.
public:
property double Opacity { double get(); void set(double value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.OpacityConverter))]
public double Opacity { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.OpacityConverter))>]
member this.Opacity : double with get, set
Public Property Opacity As Double
The level of opacity for the form. The default is 1.00.
- Attributes
The following example demonstrates how to create a form that is displayed with an opacity level of 75 percent. It 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 also sets the Size property to provide a larger sized form than the default size of the form.
This example assumes that the CreateMyOpaqueForm
method is called from another form in an event handler or other method.
private:
void CreateMyOpaqueForm()
{
// Create a new form.
Form^ form2 = gcnew 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 = 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();
}
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();
}
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
The Opacity property enables you to specify a level of transparency for the form and its controls. When this property is set to a value less than 100 percent (1.00), the entire form, including borders, is made more transparent. Setting this property to a value of 0 percent (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 percent (0.00) and gradually increasing the value until it reaches 100 percent (1.00).
Opacity differs from the transparency provided by 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.
This property is not supported when RightToLeftLayout is true
.
The Opacity property depends on the Layered Windows API. For more information, see Layered Windows.
Prodotto | Versioni |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Feedback su .NET
.NET è un progetto di open source. Selezionare un collegamento per fornire feedback: