Programación General > Visual C++
Cambiar Color Label
Perla_kiko:
Como se puede cambiar el color de un label?
navisoft:
Para hacer eso y mas sobrecargas la funcion Control Color (OnCtlColor) a tu dialogo:
Agregar una nueva variable CBrush a tu dialogo:
CBrush m_brush;
agregas la notificacion WM_CTLCOLOR a tu dialogo y quedará asi:
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
Y escribes el siguiente codigo para cambiar el color de fuente:
--- Código: Text ---HBRUSH CDialogoPruebaDlg::OnCtlColor(CDC* pDC , CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor == CTLCOLOR_STATIC) { if (pWnd->GetDlgCtrlID() == IDC_STATIC_COLORIDO) { pDC->SetTextColor(RGB(255, 0, 0)); // Rojo } } return hbr;} Si lo que quieres es cambiar el color de fondo haces:
--- Código: Text ---HBRUSH CDialogoPruebaDlg::OnCtlColor(CDC* pDC , CWnd* pWnd, UINT nCtlColor) { COLORREF color = RGB(255, 0, 0); // Rojo pDC->SetBkColor(color); if (m_brush.GetSafeHandle() == NULL) { m_brush.CreateSolidBrush(color); } if (nCtlColor == CTLCOLOR_STATIC) { if (pWnd->GetDlgCtrlID() == IDC_STATIC_COLORIDO) { hbr = (HBRUSH) m_brush.GetSafeHandle(); } } return hbr; }
Perla_kiko:
Me da error en el IDC_SATATIC_COLORIDO es alguna constante? o que libreria me falta?
Perla_kiko:
Por cirto si lo quiero poner en negrita?
Diodo:
Hola
IDC_STATIC_COLORIDO deberia ser el identificador de el label al cual quieres cambiar el color.
para mas informacion mirate este link
http://msdn.microsoft.com/library/default.....onctlcolor.asp
saludos
Navegación
[#] Página Siguiente
Ir a la versión completa