Hai Vaknin
Hai Vaknin

Reputation: 37

Mfc Dialog change color button

Thanks for your help In solving my problem I try to add a button that can change the background of the dialog to a different color i using visual studio 2010 but i think its might be wrong way to do that

    void PainterDlg::OnBnClickedButton7()
    {
    CBrush m_brush; 
    m_brush.CreateSolidBrush(RGB(255, 255, 255));
    return m_brush;
    }

Or it should look like this

    void PainterDlg::OnBnClickedButton7()
    {
    CBrush m_brush; 
    m_brush.CreateSolidBrush(RGB(255, 255, 255));
    return m_brush;
    }

both ways are not work for me thankS in advance

Upvotes: 1

Views: 11161

Answers (2)

Tom Tom
Tom Tom

Reputation: 1209

That is not so easy with CButton. (you have to draw all yourself in OnDrawItem, OnCtlColor)

A simpler way is to use CMFCButton. Add a Member Variable for your Button (with MFC-ClassWizzard) and change it to CMFCButton. Here an example to change the color button in green.

void CColorButtonSimpleDlg::OnBnClickedMyColorbtn()
{
  // add a Member Variable for your Button
  // Change it to CMFC Button

  // CMFCButton m_myBtn;     declared in Header-File  *.h 
  m_myBtn.EnableWindowsTheming(FALSE);      // (important!)
  m_myBtn.SetFaceColor(RGB(0, 255, 0));     // Change to your desired Background Color
  m_myBtn.SetTextColor(RGB(255, 255, 255)); // Change it to your desired Foreground Color

}

Upvotes: 5

Hai Vaknin
Hai Vaknin

Reputation: 37

Nvm found it

    int r,b,g; 
    r=rand()%255;
    b=rand()%255;
    g=rand()%255;
    CBrush myb;
    myb.CreateSolidBrush(RGB(r,b,g));
    dc2.FillRect(&rect,&myb);

Upvotes: -1

Related Questions