Form.Opacity 屬性

定義

取得或設定表單的透明度等級。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 example demonstrates how to create a form that is displayed with an opacity level of 75 percent. 它會建立位於畫面中央的新表單,並設定 Opacity 屬性來變更表單的不透明度層級。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. 此範例也會設定 Size 屬性,以提供比表單的預設大小更大的大小表單。The example also sets the Size property to provide a larger sized form than the default size of the form.

這個範例假設從事件處理常式或其他方法中的另一個表單呼叫 CreateMyOpaqueForm 方法。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

備註

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 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.

trueRightToLeftLayout 時,不支援這個屬性。This property is not supported when RightToLeftLayout is true.

Opacity 屬性取決於多層式 Windows API。The Opacity property depends on the Layered Windows API. 如需詳細資訊,請參閱分層視窗For more information, see Layered Windows.

適用於

另請參閱