Form.Opacity Form.Opacity Form.Opacity Form.Opacity Property

定义

获取或设置窗体的不透明度级别。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; }
member this.Opacity : double with get, set
Public Property Opacity As Double

属性值

窗体的不透明度级别。The level of opacity for the form. 默认值为 1.00。The default is 1.00.

示例

下面的代码示例演示如何创建带有 75%的不透明度级别显示的窗体。The following code example demonstrates how to create a form that is displayed with an opacity level of 75 percent. 该代码示例创建新的窗体,位于与屏幕的中央Opacity属性设置为更改窗体的不透明度级别。The code example 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. 代码示例还将设置Size属性以提供更大大小超过默认大小的窗体的窗体。The code example also sets the Size property to provide a larger sized form than the default size of the form. 编写此代码示例时,在此示例中定义的方法从另一种形式的事件处理程序或其他方法中调用的假设。This code example was written under the assumption that the method defined in this example 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

注解

Opacity属性可以指定为窗体及其控件的透明度级别。The Opacity property enables you to specify a level of transparency for the form and its controls. 当此属性设置为小于 100%(1.00) 的值时,则整个窗体,包括边框、 由更加透明。When this property is set to a value less than 100 percent (1.00), the entire form, including borders, is made more transparent. 此属性设置为值为 0%(0.00) 使窗体完全不可见。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. 例如,您可以阶段窗体到视图通过设置Opacity属性设置为 0%(0.00) 和逐渐增加的值,直到它达到 100%(1.00) 的值。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 不同于由提供的透明度TransparencyKey,后者只能使窗体,并且其控件完全透明如果中指定的值与相同的颜色TransparencyKey属性。Opacity differs from the 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.

此属性不是支持何时RightToLeftLayouttrueThis property is not supported when RightToLeftLayout is true.

Opacity属性取决于分层 Windows API 引入 Windows 2000。The Opacity property depends on the Layered Windows API that was introduced with Windows 2000. 有关详细信息,请参阅"分层 Windows:新建和的方式使用半透明度在 Windows 应用程序中的透明效果"上的平台 SDK 文档中 http://msdn.microsoft.com For more information, see the "Layered Windows: A New Way to Use Translucency and Transparency Effects in Windows Applications" in the Platform SDK documentation at http://msdn.microsoft.com.

适用于

另请参阅