Han Tran
Han Tran

Reputation: 2093

Set focus (boundary) for radiobutton

I have a button which is rdbAuto, when form is load, rdbAuto will be checked, I want to set the focus (boundary) for this radiobutton, how can I do that?

Upvotes: 1

Views: 2717

Answers (1)

wdavo
wdavo

Reputation: 5110

You can override the RadioButton control with something like this

  public class SuperRadioButton : RadioButton
  {
    private bool showFocusCues = false;

    protected override void InitLayout()
    {
      this.GotFocus += (sender, args) =>
      {
        showFocusCues = true;
      };

      this.LostFocus += (sender, args) =>
      {
        showFocusCues = false;
      };
    }

    protected override bool ShowFocusCues
    {
      get
      { 
        return showFocusCues;
      }
    }

  }

This will force the boundary to be shown whenever the radio button has focus.

Use this control instead of the standard radio button and then call the Focus method in the Form_Shown event

private void Form1_Shown(object sender, EventArgs e)
{
  superRadioButton1.Focus();
}

Upvotes: 2

Related Questions