如何改变按钮的颜色?

crs96321 2003-08-12 04:59:51
我想改变按钮的颜色!不知道如何做?请大侠帮忙!
...全文
120 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouyong0371 2003-08-26
  • 打赏
  • 举报
回复
可以在按钮上边放图片。

或者设置按钮的Owner Draw属性。
然后:

void COwnerDrawDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
char btnText[16];
HBRUSH hBrush ;
GetDlgItemText(lpDrawItemStruct->CtlID,btnText,16);
hBrush=CreateSolidBrush(RGB(213,192,228));
hBrush=(HBRUSH) SelectObject (lpDrawItemStruct->hDC,hBrush);
SetBkColor(lpDrawItemStruct->hDC,RGB(213,192,228));
SetTextColor(lpDrawItemStruct->hDC,RGB(0,0,255));
Rectangle(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);

DrawText(lpDrawItemStruct->hDC,btnText,-1,&lpDrawItemStruct->rcItem,
DT_SINGLELINE|DT_CENTER|DT_VCENTER);
DeleteObject(SelectObject(lpDrawItemStruct->hDC,hBrush));


if (lpDrawItemStruct->itemState & ODS_SELECTED)
InvertRect (lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem);
}

czlvc 2003-08-26
  • 打赏
  • 举报
回复
方法有两种:
1:自己画
2:处理WM_CTLCOLOR
kinogre 2003-08-26
  • 打赏
  • 举报
回复
唯一的办法,从CButton派生一个,自己画.

2,586

社区成员

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

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