Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6904455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:03:48+00:00 2026-05-27T08:03:48+00:00

I have a child form that I load from a parent form. The parent

  • 0

I have a child form that I load from a parent form. The parent form is NOT a MDI parent.
I would like to do the following:

I would like to disable the dotted/dashed rectangle around controls that have focus, particularly Buttons and RadioButtons.

Currently I am using the following code:

foreach (System.Windows.Forms.Control control in this.Controls)
{
    // Prevent button(s) and RadioButtons getting focus
    if (control is Button | control is RadioButton)
    {
        HelperFunctions.SetStyle(control, ControlStyles.Selectable, false);
    }
}

where my SetStyle method is

public static void SetStyle(System.Windows.Forms.Control control, ControlStyles styles,
    bool newValue)
{
    // .. set control styles for the form
    object[] args = { styles, newValue };

    typeof(System.Windows.Forms.Control).InvokeMember("SetStyle",
        BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
        null, control, args);
}

Needless to say, this does not seem to work. I am not sure what I am missing here. Any suggestions and/or advice would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:03:48+00:00Added an answer on May 27, 2026 at 8:03 am

    Well, I think I have found sort of a solution. The solution resolves the focus rectangle issue but does not answer the question of what was wrong with the original code posted. This is my understanding of the rectangle issue….please feel free to correct me if I got any of this wrong.

    It would appear that there are two types of dashed/dotted rectangles: rectangles that indicate that a control is focused, and rectangles that indicate that a control is the default control. Both of these situation require you to create a custom class for the control In my case the control of interest was a RadioButton. So here is the code:

    public class NoFocusRadioButton: RadioButton
    {
        // ---> If you DO NOT want to allow focus to the control, and want to get rid of
        // the default focus rectangle around the control, use the following ...
    
        // ... constructor
        public NoFocusRadioButton()
        {
            // ... removes the focus rectangle surrounding active/focused radio buttons
           this.SetStyle(ControlStyles.Selectable, false);
        }
    }
    

    or use the following:

    public class NoFocusRadioButton: RadioButton
    {
        // ---> If you DO want to allow focus to the control, and want to get rid of the
        // default focus rectangle around the control, use the following ...
    
        protected override bool ShowFocusCues
        {
            get
            {
                return false;
            }
        }
    }
    

    I am using the first (constructor code) approach to not allow input focus.

    This all works great to solve the rectangle problem but I still don’t understand why the initial code did not work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some values that post back to a parent form from a child
I have a child form that is throwing an ApplicationException in the Load event
I have a MDI container form, and some child forms that update their title
I have a need to close a parent form from within child form from
I have a form that can spawn a child form, something like: Private Sub
I have a MDI Child Form which contains a DataGridView that is updated continuously
I have a form that acts as MDI parent form and several other forms
I have a .NET MDI form based application. I would like to contain errors
I have a main form, and a floating child form that is non-modal. The
I have a parent form and a child form. I need to open the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.