Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CButton changing background color

CButton changing background color

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sakhalean
    wrote on last edited by
    #1

    Hi all, I have a form view there I am having checkbox buttons. Now i want to change the background color of the button. I am using OnCtlColor() fn but it is not working.

    M 1 Reply Last reply
    0
    • S Sakhalean

      Hi all, I have a form view there I am having checkbox buttons. Now i want to change the background color of the button. I am using OnCtlColor() fn but it is not working.

      M Offline
      M Offline
      Mohan Ramachandra
      wrote on last edited by
      #2

      Try this

      // Add a CBrush member variable 
      CBrush m\_brushBK;
      

      In OnInitialUpdate function

      m\_brushBK.CreateSolidBrush(RGB(200,200,0));//Set brush color
      

      In the OnCtlColor function

      HBRUSH CtestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
      {

      if(pWnd->GetDlgCtrlID()==IDC\_CHECK1)// Control ID of the Check box
      {
      	return m\_brushBK;
      }
      else
      {
      	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);	
      	return hbr;
      }
      

      }

      S 1 Reply Last reply
      0
      • M Mohan Ramachandra

        Try this

        // Add a CBrush member variable 
        CBrush m\_brushBK;
        

        In OnInitialUpdate function

        m\_brushBK.CreateSolidBrush(RGB(200,200,0));//Set brush color
        

        In the OnCtlColor function

        HBRUSH CtestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
        {

        if(pWnd->GetDlgCtrlID()==IDC\_CHECK1)// Control ID of the Check box
        {
        	return m\_brushBK;
        }
        else
        {
        	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);	
        	return hbr;
        }
        

        }

        S Offline
        S Offline
        Sakhalean
        wrote on last edited by
        #3

        OK thank you it is working

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups