Color.Inequality(Color, Color) 運算子

定義

測試兩個指定的 Color 結構是否不同。

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 op_Inequality : System.Drawing.Color * System.Drawing.Color -> bool
Public Shared Operator != (left As Color, right As Color) As Boolean

參數

left
Color

Color,位在不等比較運算子的左方。

right
Color

Color,位在不等比較運算子的右方。

傳回

如果這兩個 Color 結構不同,則為 true;否則為 false

範例

下列程式代碼範例示範 Inequality 運算符和 SystemColors 類別。 此範例的設計目的是要與包含名為 Button2之按鈕的 Windows Form 搭配使用。 將下列程式代碼貼到表單中,並將 Button2_Click 方法與按鈕的事件 Click 產生關聯。

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

   if (  !(this->Font->Bold) )
   {
      this->Font = gcnew System::Drawing::Font( this->Font,FontStyle::Bold );
   }
}
private void Button2_Click(System.Object sender, System.EventArgs e)
{

    if (this.BackColor != SystemColors.ControlDark)
    {
        this.BackColor = SystemColors.ControlDark;
    }
    if (!(this.Font.Bold))
    {
        this.Font = new Font(this.Font, FontStyle.Bold);
    }
}
Private Sub Button2_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button2.Click

    If (Color.op_Inequality(Me.BackColor, SystemColors.ControlDark)) Then
        Me.BackColor = SystemColors.ControlDark
    End If
    If Not (Me.Font.Bold) Then
        Me.Font = New Font(Me.Font, FontStyle.Bold)
    End If
End Sub

備註

這個方法會比較結構超過ARGB值 Color 。 它也會比較某些狀態旗標。 如果您想要只比較兩 Color 個結構的ARGB值,請使用 ToArgb 方法。

適用於