Form.Opacity 屬性

定義

取得或設定表單的透明度等級。

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

屬性值

表單的透明度等級。 預設值為 1.00。

屬性

範例

下列範例示範如何建立顯示不透明度層級為 75% 的表單。 它會建立位於畫面中央的新表單,並將 Opacity 屬性設定為變更表單的不透明度層級。 此範例也會設定 Size 屬性,以提供大於表單預設大小的表單。

這個範例假設 CreateMyOpaqueForm 方法是從事件處理常式或其他方法中的另一個表單呼叫。

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 可讓您指定表單及其控制項的透明度層級。 當此屬性設定為小於 100% (1.00) 的值時,整個表單包括框線會變得更透明。 將此屬性設定為 0% (0.00) 讓表單完全不可見。 您可以使用這個屬性來提供不同層級的透明度,或提供效果,例如在檢視中或離開檢視時分段表單。 例如,您可以將 屬性設定 Opacity 為 0% (0.00) ,並逐漸增加值,直到其達到 1.00% (1.00) ,以將表單分階段為檢視。

Opacity 不同于 所提供的 TransparencyKey 透明度,只有在表單及其控制項與 屬性中指定的 TransparencyKey 值相同時,才會讓表單及其控制項完全透明。

當 為 trueRightToLeftLayout ,不支援這個屬性。

屬性 Opacity 取決於分層 Windows API。 如需詳細資訊,請參閱 分層式 Windows

適用於

另請參閱