CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    how to change Button Text Color

    How can i change the command button text color , run time also.


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: how to change Button Text Color

    There are two ways of doing this -

    1. Subclassing - lot's of code to write for the handling of painting the button text. I think you can find examples at either http://www.matthart.com or http://www.mvps.org/vbnet

    2. Cheat !

    You can place a checkbox on a form and set it's style to '1 - Graphical'. This then looks just like a button but you can change it's back and forecolor at runtime. All you need to be careful of is the click event where the button can stay 'clicked' - just paste this code into a form (FORM1) with a graphical check box (Check1) :


    private Sub Check1_Click()
    Check1.Value = vbUnchecked
    Check1.ForeColor = RGB(Rnd(1) * 255, Rnd(1) * 255, Rnd(1) & 255)
    Check1.BackColor = RGB(Rnd(1) * 255, Rnd(1) * 255, Rnd(1) & 255)
    End Sub

    private Sub Form_Load()
    '
    ' Make sure Check1 has style set to '1-Graphical'
    '
    Check1.ForeColor = vbBlue
    End Sub




    - The only problem I can see doing it this way is that CheckBoxes can't have the 'default' or 'cancel' properties (although you could use keypreview to do the same things).



    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: how to change Button Text Color

    BTW, i do precisely that soln of Chris.. use Check Boxes.. and it works quite fine for me

    RK

  4. #4
    Guest

    Re: how to change Button Text Color

    If you go to http://www.castlems.com/ammb.html they have a ActiveX control that you can put into your project that allows you to have alot of flexibility in designing all types of buttons etc.

    I use this alot in my apps and have never had any problems.

    Hope this helps
    tcompe


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