如何更改对话框中特定按钮的颜色 [英] How can I change a color for a specific button on my dialog
本文介绍了如何更改对话框中特定按钮的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为RoundBtn.cpp的源文件及其头文件RoundBtn.h
这两个文件负责着色我的Dialog上的entier按钮。我需要做的是给我的一个按钮一个特殊的颜色。下面给出了一些着色所有按钮的代码。
I have a source file called RoundBtn.cpp with its header file RoundBtn.h
these two files are responsable for coloring the entier buttons on my Dialog. What i need to do is to give one of my button a special color. Some of the code for coloring all buttons is given below.
void RoundBtn::DrawItem(LPDRAWITEMSTRUCT lp)
{
CRect rc = lp->rcItem;
CDC dc;
dc.Attach(lp->hDC);
dc.SetBkMode(TRANSPARENT);
CBrush br;
br.CreateStockObject(NULL_BRUSH);
dc.SelectObject(&br);
if (is_pressed) // when the button is pressed
{
CPen pen(PS_SOLID, 2, RGB(0,0,0));
dc.SelectObject(&pen);
CBrush *pBrush=new CBrush(RGB(220,100,220));
dc.SelectObject(pBrush);
dc.RoundRect(0, 0, rc.Width(), rc.Height(), rc.Height()/1, rc.Height()/1); // Round the Buttons
dc.SetTextColor(RGB(0, 0, 0));
什么我试过了:
我可以在主文件上更改什么,或者我可以在主文件上调用什么来为按钮着色。按钮ID Adress是
What I have tried:
What sould i change on my main file or what sould i call on my main file to color the button. the button ID Adress is
IDM_APPLY
,其功能是
and its function is
void CVCDlg::Apply1()
{
OnButtonApplyrange();
}
推荐答案
用于构造* pBrush的颜色是需要调整的颜色。您可以将颜色变量(COLORREF)设置为RoundBtn类的成员,并在类构造函数中将其设置为220,100,220。然后添加一个方法来设置颜色成员,如果你愿意,你可以让每个按钮都是不同的颜色。
The color used to construct the *pBrush is the one that needs to be adjusted. You could make a color variable (COLORREF) a member of the RoundBtn class and set it to 220,100,220 in the class constructor. Then add a method to set the color member and you can have each button be a different color if you wanted to.
这篇关于如何更改对话框中特定按钮的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文