Change the Foreground and Background Colour of Staic Text Control in VC++
2006-10-18 23:09
916 查看
overrider OnCtlColor for WM_CTLCOLOR for your dialog like following to set background and text color :
e.g.
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->m_hWnd== GetDlgItem(IDC_TEXT)->m_hWnd) //Use static ID of your static text control
{
pDC->SetBkColor( RGB( 255, 0, 0 ) ); //red background
pDC->SetTextColor( RGB( 255, 255, 255 ) ); //white text
return hbr;
}
return hbr;
}
Otherwise derive your own control....like following
http://www.codeproject.com/staticctrl/coloredit_colorstatic.asp
e.g.
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->m_hWnd== GetDlgItem(IDC_TEXT)->m_hWnd) //Use static ID of your static text control
{
pDC->SetBkColor( RGB( 255, 0, 0 ) ); //red background
pDC->SetTextColor( RGB( 255, 255, 255 ) ); //white text
return hbr;
}
return hbr;
}
Otherwise derive your own control....like following
http://www.codeproject.com/staticctrl/coloredit_colorstatic.asp
相关文章推荐
- (Sharepoint 2010) Change the background and font color of text for a web part header
- Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
- Networks of Innovation : Change and Meaning in the Age of the Internet
- How To Change the Background Color of a Tab Control
- Change the background color of the header of a List Control
- The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2
- How to change the Text color of Menu item in Android?
- Change the ICON of your website in favorite,address and shortcut bars
- How to change the text color of the selected property sheet tab in Visual C++
- An easy way to change colour in text control
- Coloring the Console Application (AddingText and Background color in C#)
- Launching Tasks in the Foreground and Background
- Networks of Innovation: Change and Meaning in the Age of the Internet
- How to enumerate the system fonts in the combobox control using VC++ - 用VC++如何在ComboBox控件中枚举系统字体
- How do I add new state and change the workflow of Purchase Order?
- About the Rebase and Bind operation in the production of software
- Advances in Mobile and Wireless Communications: Views of the 16th IST Mobile and Wireless Communicat
- Analyzing billions of credit card transactions and serving low-latency insights in the cloud
- sql: Query to Display Foreign Key Relationships and Name of the Constraint for Each Table in Database
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox