共用方式為


ColorTranslator.ToWin32(Color) 方法

定義

將指定的 Color 結構轉換為 Windows 色彩。

public:
 static int ToWin32(System::Drawing::Color c);
public static int ToWin32 (System.Drawing.Color c);
static member ToWin32 : System.Drawing.Color -> int
Public Shared Function ToWin32 (c As Color) As Integer

參數

c
Color

要轉換的 Color 結構。

傳回

Windows 色彩值。

範例

下列範例是設計來搭配 Windows Forms 使用,而且需要 PaintEventArgse,這是事件處理程序的參數Paint。 程序代碼會將 Color 結構轉譯為代表 Windows 色彩的整數,然後顯示含有結果字串的消息框。

public:
   void ToWin32_Example( PaintEventArgs^ /*e*/ )
   {
      // Create an instance of a Color structure.
      Color myColor = Color::Red;

      // Translate myColor to an OLE color.
      int winColor = ColorTranslator::ToWin32( myColor );

      // Show a message box with the value of winColor.
      MessageBox::Show( winColor.ToString() );
   }
public void ToWin32_Example(PaintEventArgs e)
{
    // Create an instance of a Color structure.
    Color myColor = Color.Red;
             
    // Translate myColor to an OLE color.
    int winColor = ColorTranslator.ToWin32(myColor);
             
    // Show a message box with the value of winColor.
    MessageBox.Show(winColor.ToString());
}
Public Sub ToWin32_Example(ByVal e As PaintEventArgs)

    ' Create an instance of a Color structure.
    Dim myColor As Color = Color.Red

    ' Translate myColor to an OLE color.
    Dim winColor As Integer = ColorTranslator.ToWin32(myColor)

    ' Show a message box with the value of winColor.
    MessageBox.Show(winColor)
End Sub

適用於