How to change the background color of an Edit Box
2006-10-17 22:06
751 查看
How to change the background color of an Edit Box
http://www.codeproject.com/cpp/cppfaq10dec04-23jan05.asp
You can change the background color of an edit control in a dialog by handling the
class MyDialog : public CDialog {
//...
COLORREF _BkgColor;
HBRUSH _BkgBrush;
};
BOOL MyDialog::OnInitDialog()
{
//...
_BkgColor = RGB(0,255,0);
_BkgBrush = ::CreateSolidBrush(_BkgColor);
}
HBRUSH MyDialog::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor )
{
hbr = CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
if (pWnd()->GetDlgCtrlId() == IDC_MY_EDIT_CONTROL) {
pDC->SetBkColor(_BkgColor);
hbr = _BkgBrush;
}
return hbr;
}
In the
http://www.codeproject.com/cpp/cppfaq10dec04-23jan05.asp
You can change the background color of an edit control in a dialog by handling the
WM_CTLCOLORmessage in the dialog
class MyDialog : public CDialog {
//...
COLORREF _BkgColor;
HBRUSH _BkgBrush;
};
BOOL MyDialog::OnInitDialog()
{
//...
_BkgColor = RGB(0,255,0);
_BkgBrush = ::CreateSolidBrush(_BkgColor);
}
HBRUSH MyDialog::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor )
{
hbr = CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
if (pWnd()->GetDlgCtrlId() == IDC_MY_EDIT_CONTROL) {
pDC->SetBkColor(_BkgColor);
hbr = _BkgBrush;
}
return hbr;
}
In the
OnInitDialog()handler for the dialog, we initialize the background color value and create a brush in that color. The
WM_CTLCOLORhandler is called
OnCtlColor. The edit control for which we want to change the color has the resource ID
IDC_MY_EDIT_CONTROL. We set the text background to our background color using
SetBkColor(), and the overall background for the control by returning the brush we created.
相关文章推荐
- how to change the background color of actionbar
- How to change the background color of form using C++ - 如何用C++改变窗体的颜色
- How To Change the Background Color of a Tab Control
- qt 之 How to Change the Background Color of QWidget
- How can I set the background of UITableView (the tableview style is "Grouped") to use an image?
- how to change the background of actionbar.tab
- How to change the size of the button of an android checkbox?
- How to change the highlight color in autocomplete box in Eclipse
- How to customize the background color of a UITableViewCell?
- uiview 某点返回 色值 How to get the color of a pixel in an UIView?
- How to change the implementation (detour) of an externally declared function
- How to change the Text color of Menu item in Android?
- How to programmatically change the default view of an InfoPath form
- How to change the output color of echo in Linux
- How to change the color of a CEikLabel
- How to Change the Size of a Box-Plot Label in MATLAB
- How to customize the background color of a UITableViewCell? 修改UITableViewCell背景色
- How to change background color of gedit embedded terminal
- How to change the text color of the selected property sheet tab in Visual C++
- how to edit the grub to change the sequance of system