Results 1 to 6 of 6

Thread: [RESOLVED] Cmd button fore colour

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    Resolved [RESOLVED] Cmd button fore colour

    Been reading a bit about this and it looks like the best option
    is to use a Check box or radio button with Style=1.

    After clicking though, it leaves a marquee dotted line on the control until you click on something else.
    Can this be removed automatically anyhow?

  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Cmd button fore colour

    Alex

    I think what you are referring to is a standard Cmd button feature ..
    it is to let you know that said button has Focus.

    If this is in fact the issue, then maybe if you set Focus to the Form,
    the dashed lines will go away.

    Perhaps you could post a screenshot.

    Spoo

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Cmd button fore colour

    Command Button Fore Colour (Color)....? Are you simply wanting to change the FORECOLOR (what is written on a cmd button)...here is a great example of doing jsut that...

    EDIT...sorry-- attachment had my exe...will resend without if you want it...Bonnie has solution....
    Last edited by SamOscarBrown; Apr 17th, 2013 at 03:48 PM.

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Cmd button fore colour

    Try sending your buttons the WM_KILLFOCUS message:

    Code:
    Private Const WM_KILLFOCUS As Long = &H8
    
    Private Declare Function SendMessageW Lib "user32.dll" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Sub Check1_Click()
        SendMessageW Check1.hWnd, WM_KILLFOCUS, 0&, 0&
    End Sub
    
    Private Sub Command1_Click()
        SendMessageW Command1.hWnd, WM_KILLFOCUS, 0&, 0&
    End Sub
    
    Private Sub Option1_Click()
        SendMessageW Option1.hWnd, WM_KILLFOCUS, 0&, 0&
    End Sub
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Cmd button fore colour

    Alex

    You did not ask for this, but you can very easily change the BackColor
    of a CmdButton ,,

    1. Manually set the button's Style Property to 1 - Graphical. It is read-only, can't be done by code
    2. To set the color, you can do it manually (BackColor Property) or by code.

    Spoo

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,535

    Re: [RESOLVED] Cmd button fore colour

    Thanks very much everyone. Nice example too Sam but here it fires "Visual Basic has encountered a problem...." when you close it after 8 or so random clicks.
    Bonnie's solution was brilliant as it also depresses the button and adding Me.Option1.Value = False makes it behave exactly like a normal button. Wonderful!

    Spoo, never knew that - always assumed BackColor would work - guess I never tried it. Thanks

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