radion button 和 check box的背景颜色怎么改啊?

kevinaniu 2006-05-13 05:49:40
用SetWindowText能够改文字,但是文字下面的底色怎么改啊?因为我想让其跟最下面的颜色一样,但是现在是在我的对话框上有个白条,好难看,请帮助。感谢!!
...全文
193 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxk122481 2006-05-14
  • 打赏
  • 举报
回复
确实可以
但是可不可以改变Radio的字体颜色呢?
因为可能控件所在窗体的颜色刚好为黑色,那岂不是看不到字了?
lixiaosan 2006-05-14
  • 打赏
  • 举报
回复
HBRUSH CTest6Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

switch(nCtlColor)
{
case CTLCOLOR_EDIT:
if(pWnd->GetDlgCtrlID() == IDC_EDIT1)
{
static HBRUSH hbrEdit = ::CreateSolidBrush( RGB(255, 0, 0) );
pDC->SetBkMode(TRANSPARENT); //透明
pDC->SetTextColor( RGB(0, 255, 0) );
return hbrEdit;
}
}

// TODO: Return a different brush if the default is not desired
return hbr;
}
snowbirdfly 2006-05-14
  • 打赏
  • 举报
回复
建议楼主处理OnCtlColor消息~~~
在VC技术内幕里面有提到了该问题~~~
Setting the Color for the Dialog Background and for Controls
说明如下:
The parent dialog is sent a WM_CTLCOLOR message for each control immediately before the control is displayed. A WM_CTLCOLOR message is also sent on behalf of the dialog itself. If you map this message in your derived dialog class, you can set the foreground and background text colors and select a brush for the control or dialog nontext area.
HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor == CTLCOLOR_EDIT)//假如是EDIT控件
{
pDC->SetBkColor(RGB(255, 255, 0)); // yellow
return m_hYellowBrush;
}
if (nCtlColor == CTLCOLOR_DLG) //是DLG控件
{
pDC->SetBkColor(RGB(255, 0, 0)); // red
return m_hRedBrush;
}
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
这样就可以达到效果 ~~~
Contains one of the following values, specifying the type of control:
• CTLCOLOR_BTN Button control
• CTLCOLOR_DLG Dialog box
• CTLCOLOR_EDIT Edit control
• CTLCOLOR_LISTBOX List-box control
• CTLCOLOR_MSGBOX Message box
• CTLCOLOR_SCROLLBAR Scroll-bar control
• CTLCOLOR_STATIC Static control
上面为常见控件的标示值.
这个是MSDN里面的介绍~~
soaroc 2006-05-14
  • 打赏
  • 举报
回复
同样可以,使用SetTextColor或者SetForeColor(我忘了是那一个了,还是都可以?,你试一试),地方仍在楼上所说的函数里
Stefine 2006-05-13
  • 打赏
  • 举报
回复
把控件变成透明的就可以了

响应OnCtlColor消息

jxk122481 2006-05-13
  • 打赏
  • 举报
回复
我也想知道——

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧