Color.Equality(Color, Color) 運算子

定義

測試兩個指定的 Color 結構是否相等。Tests whether two specified Color structures are equivalent.

public:
 static bool operator ==(System::Drawing::Color left, System::Drawing::Color right);
public static bool operator == (System.Drawing.Color left, System.Drawing.Color right);
static member ( = ) : System.Drawing.Color * System.Drawing.Color -> bool
Public Shared Operator == (left As Color, right As Color) As Boolean

參數

left
Color

Color,位在等號比較運算子的左方。The Color that is to the left of the equality operator.

right
Color

Color,位在等號比較運算子的右方。The Color that is to the right of the equality operator.

傳回

如果這兩個 Color 結構相等,則為 true,否則為 falsetrue if the two Color structures are equal; otherwise, false.

範例

下列程式碼範例示範 Equality 運算子和 SystemColors 類別。The following code example demonstrates the Equality operator and the SystemColors class. 這個範例是設計來搭配 Windows Form 使用,其中包含名為 Button1 的按鈕。This example is designed to be used with a Windows Form that contains a button named Button1. 將下列程式碼貼到您的表單中,並將 Button1_Click 方法與按鈕的 Click 事件產生關聯。Paste the following code into your form and associate the Button1_Click method with the button's Click event.

void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   if ( this->BackColor == SystemColors::ControlDark )
   {
      this->BackColor = SystemColors::Control;
   }
}
private void Button1_Click(System.Object sender, System.EventArgs e)
{

    if (this.BackColor == SystemColors.ControlDark)
    {
        this.BackColor = SystemColors.Control;
    }
}
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    If (Color.op_Equality(Me.BackColor, SystemColors.ControlDark)) Then
        Me.BackColor = SystemColors.Control
    End If
End Sub

備註

這個方法會比較大於 Color 結構的 ARGB 值。This method compares more than the ARGB values of the Color structures. 它也會比較一些狀態旗標。It also does a comparison of some state flags. 如果您只想要比較兩個 Color 結構的 ARGB 值,請使用 ToArgb 方法進行比較。If you want to compare just the ARGB values of two Color structures, compare them using the ToArgb method.

適用於