共用方式為


CColorDialog::OnColorOK

驗證色彩的覆寫輸入至 對話方塊。

virtual BOOL OnColorOK( );

傳回值

如果不是零,則對話方塊不應該取消;否則接受輸入的色彩的 0。

備註

請覆寫這個函式,只有在您要讓使用者在色彩對話方塊選取色彩的自訂驗證。

使用者可以透過下列兩種方法之一:選取色彩。

  • 按一下色彩的色板。 所選取色彩的 RGB 值在適當的 RGB 編輯方塊會反映。

  • 輸入 RGB 在編輯方塊中的值。

覆寫 OnColorOK 可讓您拒絕使用者輸入的所有應用程式特定原因的常見色彩對話方塊的色彩。

通常,您不需要使用這個函式,因為此種架構會提供色彩的預設驗證並顯示訊息方塊,如果提供了不正確的色彩編碼。

您可以呼叫 SetCurrentColorOnColorOK 內強制色彩選擇。 一旦 OnColorOK 引發 (也就是使用者按一下 接受變更色彩的 [確定] ),您可以呼叫 GetColor 取得新色彩的 RGB 值。

範例

// Override OnColorOK to validate the color entered to the 
// Red, Green, and Blue edit controls. If the color 
// is BLACK (i.e. RGB(0, 0,0)), then force the current color 
// selection to be the color initially selected when the 
// dialog box is created. The color dialog won't close so 
// user can enter a new color.
BOOL CMyColorDlg::OnColorOK()
{
   // Value in Red edit control.
   COLORREF clrref = GetColor();
   if (RGB(0, 0, 0) == clrref)
   {
      AfxMessageBox(_T("BLACK is not an acceptable color. ")
         _T("Please enter a color again"));

      // GetColor() returns initially selected color.
      SetCurrentColor(GetColor());        

      // Won't dismiss color dialog. 
      return TRUE;                        
   }

   // OK to dismiss color dialog. 
   return FALSE;                          
}

需求

Header: afxdlgs.h

請參閱

參考

CColorDialog 類別

階層架構圖表