CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2004
    Posts
    6

    Onctrlcolor() paint a button

    How do i paint a button Red ?

    i know that i must use OnCtrlColor , but i don't know what to write there.

    How do i call the OnCtrlColor() when the program already runs ?
    ( i know that the OnCtrlColor function is called in the beggining of the program).

  2. #2
    Join Date
    Jan 2004
    Location
    Punjab, India
    Posts
    113
    Check out thesearticles...

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    'CButton' is the only control that does not respond to the 'OnCtlColor()' message handler even though the MSDN (http://msdn.microsoft.com) explains it that way. To change the color of a 'CButton' control you have to set the style to ownerdrawn and do it yourself.

    You will find a complete 'CColorButton' class here. This class does not allow you to change the color at run-time...you will find a modified control here.

  4. #4
    Join Date
    Jun 2004
    Posts
    6

    Thanks Amit,but....

    Thank you ,but these articles helps me to create a colored buttons, what i need is : How to change color of a button that i added to the FormView. and how do i change his color on runtime ( for example - when i push him i change his color )

    i already tried :

    CDC *pDC;
    CButton *pButton1 = (CButton*) GetDlgItem(IDC_BUTTON1);
    if ( pButton1 != NULL )
    {
    pDC = pButton1->GetDC();
    pDC->SetBKColor(rgb(255,0,0);
    }
    GetDlgItem(IDC_BUTTON1)->RedrawWindow();

    Why doesn't this work?
    How do i paint a button ?

  5. #5
    Join Date
    Jan 2004
    Location
    Punjab, India
    Posts
    113
    Use the link provided by Andreas. You can use any color button class by modifing it according to your needs but you have to ownerdraw buttons if you want to change their color at any time.

  6. #6
    Join Date
    Jun 2004
    Posts
    6

    Thanks

    Thank you for your help , i found the solution in the "Microsoft Form 2.0 CommandButton" it does it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured