Bonjour,
Comment faire pour changer la couleur du texte d'un radio button, car il n'y a pas la propriété TextColor dans l'éditeur de resources ?
Merci,
Christophe
Version imprimable
Bonjour,
Comment faire pour changer la couleur du texte d'un radio button, car il n'y a pas la propriété TextColor dans l'éditeur de resources ?
Merci,
Christophe
un radio button est un CButton ;
peut-être ce code source du MSDN sera utile
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 // NOTE: CMyButton is a class derived from CButton. The CMyButton // object was created as follows: // // CMyButton myButton; // myButton.Create(_T("My button"), // WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, // CRect(10,10,100,30), pParentWnd, 1); // // This example implements the DrawItem method for a CButton-derived // class that draws the button's text using the color red. void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { UINT uStyle = DFCS_BUTTONPUSH; // This code only works with buttons. ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON); // If drawing selected, add the pushed style to DrawFrameControl. if (lpDrawItemStruct->itemState & ODS_SELECTED) uStyle |= DFCS_PUSHED; // Draw the button frame. ::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, DFC_BUTTON, uStyle); // Get the button's text. CString strText; GetWindowText(strText); // Draw the button text using the text color red. COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0)); ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER); ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
Bonjour,
Si, le radio bouton est dans une boîte de dialogue, il faut gere le message WM_CTLCOLOR par exemple
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
int nCtrlID = pWnd->GetDlgCtrlID();
if (nCtlColor == CTLCOLOR_STATIC)
{
if (nCtrlID == IDC_RADIO_MYBUTTON)
{
pDC->SetTextColor(RGB(0, 0, 255));
}
}
return hbr;
}