locked
Is there a property (not code) to alter checkbox appearance when focused? RRS feed

  • Question

  • Simply, when a user uses the keyboard to tab through all the controls instead of using the mouse, there is no way to tell when a checkbox has the focus (appearance does not change.)

    Sure, I could add code to change the appearance of checkboxes upon receiving focus, but it would be nice if there were a simple Property I could set at design time (I have a lot of them.)

    Anyone? TIA.


    • Edited by Mugsy323 Monday, March 30, 2015 4:25 PM
    Monday, March 30, 2015 4:02 PM

Answers

  • If it is set to Flat style then try changing the BackColor of the CheckBox.

        Private Sub CheckBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.Enter
            CheckBox1.BackColor = Color.FromArgb(60, Color.Red)
        End Sub
    
        Private Sub CheckBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.Leave
            CheckBox1.BackColor = Me.BackColor
        End Sub
    


    If you say it can`t be done then i`ll try it

    • Marked as answer by Mugsy323 Monday, March 30, 2015 7:41 PM
    Monday, March 30, 2015 4:47 PM

All replies

  • Simply, when a user uses the keyboard to tab through all the controls instead of using the mouse, there is no way to tell when a checkbox has the focus (appearance does not change.)

    Sure, I could add code to change the appearance of checkboxes upon receiving focus, but it would be nice if there were a simple Property I could set at design time (I have a lot of them.)

    Anyone? TIA.


     No, not that i know of.  You will need to ether add all the Enter events to one sub and all the Leave events to another and use that to change a color or border style OR create a small Checkbox class that has the code to change a color or border style and replace all your checkboxes with that class.

    If you say it can`t be done then i`ll try it

    Monday, March 30, 2015 4:12 PM
  • Your title asks about a TextBox and you question asks about a CheckBox. Both types of control have a way of showing they have focus. If I display a form that contains a TextBox and a Checkbox, I can tab through the controls, and when the TextBox has focus I see the carrot in the text area, and when the CheckBox has focus, I see the selection rectangle around the text area of the CheckBox control.

    • Proposed as answer by Cor Ligthert Monday, March 30, 2015 4:28 PM
    Monday, March 30, 2015 4:15 PM
  • Your title asks about a TextBox and you question asks about a CheckBox.

    .
    Oops. Sorry. Fixed.
    Monday, March 30, 2015 4:25 PM
  • Your title asks about a TextBox and you question asks about a CheckBox. Both types of control have a way of showing they have focus. If I display a form that contains a TextBox and a Checkbox, I can tab through the controls, and when the TextBox has focus I see the carrot in the text area, and when the CheckBox has focus, I see the selection rectangle around the text area of the CheckBox control.

     True, however if you have the BackColor of the form set to a color like DimGray or have a dark colored image behind a checkbox then it does become very hard to see.   8)

    For example, CheckBox1 has focus but you can not tell without looking real hard.


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Monday, March 30, 2015 4:35 PM
    Monday, March 30, 2015 4:31 PM
  • No, not that i know of.  You will need to ether add all the Enter events to one sub and all the Leave events to another and use that to change a color or border style OR create a small Checkbox class that has the code to change a color or border style and replace all your checkboxes with that class.

    .
    I looked into doing it with code and there does not seem to be a property I can chage that doesn't involve another action like MouseOver.

    Tried setting the border size & bordercolor via code in the "GotFocus" event and nothing happened.

    In Design, setting the Border size ("chkThumb01.FlatAppearance.BorderSize = 3") also does not change the appearance (trying different "Flatstyle" settings didn't allow me to change the border.)

    Monday, March 30, 2015 4:31 PM
  • In fact has Blackwood answered your question. If you are looking for the moment the mouse is focused you can use the focused property.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.control.focused(v=vs.110).aspx

    By the way, I'm glad that Blackwood is making the same kind of typos likewise me. It is a caret, not a carrot.


    Success
    Cor





    Monday, March 30, 2015 4:35 PM
  • If it is set to Flat style then try changing the BackColor of the CheckBox.

        Private Sub CheckBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.Enter
            CheckBox1.BackColor = Color.FromArgb(60, Color.Red)
        End Sub
    
        Private Sub CheckBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.Leave
            CheckBox1.BackColor = Me.BackColor
        End Sub
    


    If you say it can`t be done then i`ll try it

    • Marked as answer by Mugsy323 Monday, March 30, 2015 7:41 PM
    Monday, March 30, 2015 4:47 PM
  • It is a caret, not a carrot.
    LOL

    Armin

    Monday, March 30, 2015 4:55 PM
  • By the way, I'm glad that Blackwood is making the same kind of typos likewise me. It is a caret, not a carrot.


    Oops. Thanks Cor.
    Monday, March 30, 2015 4:55 PM
  • when the CheckBox has focus, I see the selection rectangle around the text area of the CheckBox control.

    .
    No. Not sure why, but I'm not getting a bounding box (the familiar dotted line) around my checkboxes.

    I finally settled for changing the "Flatstyle" in code upon gaining/losing focus. :(

    Monday, March 30, 2015 5:33 PM
  • I finally settled for changing the "Flatstyle" in code upon gaining/losing focus.

    You didn't say which events you're using but don't use .GotFocus or .LostFocus - instead, use .Enter and .Leave events.

    From this MSDN document:

    "The GotFocus and LostFocus events are low-level focus events that are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the GotFocus and LostFocus events are only used when updating UICues or when writing custom controls. Instead the Enter and Leave events should be used for all controls except the Form class, which uses the Activated and Deactivate events."


    Still lost in code, just at a little higher level.

    :-)

    Monday, March 30, 2015 6:13 PM
  • You didn't say which events you're using but don't use .GotFocus or .LostFocus - instead, use .Enter and .Leave events.
    .
    Ah, GTK. Thanks.
    Monday, March 30, 2015 7:41 PM