Button problem (.Net 2008, Framework 3.5)

When the button is focused by pressing the Tab key, the This rectangle appears. Even if the TabStop property of the button is set to false, click the mouse button, a rectangle will appear. Is it possible to stop the appearance of the rectangle? Please help. Regards.

+3
source share
2 answers

This rectangle that appears on your button is called the "focus rectangle." It indicates which control on the form has input focus.

The explanation of the problem you are working with is that even when the button is not a tab, it is still selected when it is clicked on with the mouse, and therefore the focus rectangle still appears. The property TabStoponly determines whether the control can receive focus using the key Tab, and not regardless of whether the user selects it.

A focus rectangle is useful to indicate to a user who has focus. Pressing the keys Enteror Spacewith the selected button will cause the button to be pressed. Without a focus rectangle, keyboard users may find it difficult to navigate your application.

, (, , ), Enabled False. , .

, , , ( , ), , Button. ShowFocusCues ( True Button) False. :

public class NoFocusButton : Button
{
    protected override bool ShowFocusCues
    {
        get
        {
                return false;
        }
    }
}

OnPaint . ( ), , . . .

+7
class CustomButton : System.Windows.Forms.Button
   {
       private bool _DisplayFocusCues = true;
       protected override bool ShowFocusCues
       {
           get
           {
               return _DisplayFocusCues;
           }
       }

       public bool DisplayFocusCues
       {
           get
           {
               return _DisplayFocusCues;
           }
           set
           {
               _DisplayFocusCues = value;
           }
       }
   }

DisplayFocusCues .

0

Source: https://habr.com/ru/post/1774685/


All Articles