none
CLASS FILE MAKE FOR WINDOWS FORM BUTTON CLICK ERROR FOR ArgumentException was unhandled Top-level control cannot be added to a control. RRS feed

  • Question

  • method used for 

    Content.Controls.Clear();
                control.Dock = DockStyle.Fill;
                control.BringToFront();
                control.Focus();
                Content.Controls.Add(control);

    please answer for this error

    Friday, April 3, 2020 5:40 PM

All replies

  • Please post the entire source because the above code is meaningless. You didn't show where `control` was created and how it was initialized or anything relate to `Content`. Please use the Insert Code Block tool in the editor to paste source code into this thread.

    Additionally your calls to BringToFront, Focus, etc aren't really going to work until the control is added to the parent window so that needs to happen after.

    Also please post the actual exception information including - type, message, call stack. The exact line where it is occurring in your code will more than likely identity the exact problem.


    Michael Taylor http://www.michaeltaylorp3.net

    Friday, April 3, 2020 5:55 PM
    Moderator
  • Hi MAHESH SHETE,
    Based on your description, I can't reproduce the situation. What is "Content" in your code? And could you provide more related code to reproduce it?
    >>Top-level control cannot be added to a control
    About the error, you can set TopLevel property to false.
    Here is related thread you can refer to.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 7, 2020 5:53 AM