IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

Changer couleur Texte Radio


Sujet :

MFC

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    907
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 907
    Points : 372
    Points
    372
    Par défaut Changer couleur Texte Radio
    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

  2. #2
    Expert éminent sénior
    Avatar de Mat.M
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    8 396
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2006
    Messages : 8 396
    Points : 20 507
    Points
    20 507
    Par défaut
    un radio button est un CButton ;
    peut-être ce code source du MSDN sera utile

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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);

  3. #3
    Membre régulier
    Inscrit en
    Janvier 2006
    Messages
    165
    Détails du profil
    Informations forums :
    Inscription : Janvier 2006
    Messages : 165
    Points : 106
    Points
    106
    Par défaut
    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;
    }

Discussions similaires

  1. Réponses: 3
    Dernier message: 25/04/2007, 15h25
  2. changer couleur texte d'un JLabel
    Par barbiche dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 24/04/2007, 12h07
  3. Réponses: 5
    Dernier message: 22/10/2006, 01h29
  4. [C#] Changer couleur texte d'une toolbar
    Par djoao dans le forum Windows Forms
    Réponses: 15
    Dernier message: 01/05/2006, 19h32
  5. [CSS]Changer couleur texte à partir d'une limite horizontale
    Par mathieu7497 dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 14/04/2006, 23h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo