如何更改按钮颜色按钮颜色 [英] how to change the push button colour button colour

查看:148
本文介绍了如何更改按钮颜色按钮颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


1.我正在做一个程序来更改按钮的颜色,通过单击按钮从组合框中选择颜色来更改复选框的颜色.我的问题是按钮的颜色没有改变,请帮助我改变按钮的颜色


2.如果在未从组合框中选择颜色的情况下单击了按钮,则消息必须显示为选择颜色".

3.如何更改复选框的颜色[复选框内的白色区域]

我搜索了代码,但没有得到,如果您给我代码,将会很有帮助
谢谢

这是我的代码

Hi ,
1. im doing a program to change the colour of push button,edit,check box by choosing the colour from combo box by clicking push button. My problem is the push button colour is not changing ,, please help me to change the colour of the push button


2. if the push button is clicked without choosing the colour from the combo box,, a message must appear as "select a color".

3.how to change the colour of check box[the white area inside the check box]

I searched for the code but i didnt get it,, it will be helpfull if you give me the codes
thank you

this is my code

void CComboTestDlg::OnButton1()
{
	int index = m_ColorCombo.GetCurSel();
	if(index != CB_ERR)
	{
		m_brush.DeleteObject();
		switch(index)
		{
		case 0:
		m_brush.CreateSolidBrush(RGB(0, 240, 120));
		break;
		case 1:
		m_brush.CreateSolidBrush(RGB(128, 0, 240));
		break;
		case 2:
		m_brush.CreateSolidBrush(RGB(0, 128, 0));
		break;
		case 3:
		m_brush.CreateSolidBrush(RGB(128, 128, 0));
		break;
		case 4:
		m_brush.CreateSolidBrush(RGB(0, 0, 128));
		break;
		default:
			m_brush.CreateSolidBrush(::GetSysColor(COLOR_WINDOWTEXT));
			break;
		}
		Invalidate(TRUE);

	}
	else
		{
		AfxMessageBox("Select a color  ");
		}
	
}

HBRUSH CComboTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
switch ( nCtlColor )
{
case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
case CTLCOLOR_BTN:
case CTLCOLOR_STATIC:
pDC->SetTextColor(RGB(0, 240, 120));

pDC->SetBkColor(RGB(0, 0, 0));
return (HBRUSH)(m_brush.GetSafeHandle());
case CTLCOLOR_DLG:
return static_cast<HBRUSH> ( m_brush.GetSafeHandle() );
}
// TODO: Return a different brush if the default is not desired

}


预先谢谢你
AJ


thank you in advance
AJ

推荐答案

您必须自己绘制这些控件.通常的方法是创建一个从CButton(或CCheckbox)派生的新类,并覆盖OnPaint命令.不要忘记,您还必须为控件可以具有的所有状态绘制.

那里可能已经有代码可以编辑您想要的东西了(很可能就在CodeProject上). Google是您的朋友.
You have to paint those kinds of controls yourself. The usual way to do this is to create a new class derived from CButton (or CCheckbox), and override the OnPaint command. Don''t forget that you have to also paint for ALL states the control can have.

There''s probably already code out there to do edxactly what you want (and most likely right here on CodeProject). Google is your friend.


这篇关于如何更改按钮颜色按钮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆