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 4533990
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:13:30+00:00 2026-05-21T14:13:30+00:00

I created a custom UserControl, where I support dragging and dropping of controls at

  • 0

I created a custom UserControl, where I support dragging and dropping of controls at design time. My controls are dropped into my user control correctly, however they are hidden once dropped onto the user control. To get the added control to become visible, I have to select it and click the design time IDE button “Bring to Front” to see the control added. When I rebuild the solution, the controls become hidden again.

I reproduced the issue with the following code. In the IDE I created a simple user control “MyControl”, to which I added a single Panel control docked to “Fill”. This user control “MyControl” should then be dropped onto a Windows panel. Then, drag and drop another control, such as a Label or Buton control onto the user control and it becomes hidden.

Below is the code for the user control. How can I get the controls that are dropped into the user control at design time be brought to the front automatically?

MyControl.Designer.cs:

namespace Test
{
    partial class MyControl
    {
        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(150, 150);
            this.panel1.TabIndex = 0;
            // 
            // MyControl
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.panel1);
            this.Name = "MyControl";
            this.ResumeLayout(false);

        }

        private System.Windows.Forms.Panel panel1;
    }
}

MyControl.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace Axiom.Controls
{
    [Designer(typeof(ParentControlDesigner))]
    public partial class MyControl : UserControl
    {
        public MyControl()
        {
            InitializeComponent();
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Panel ContentPanel
        {
            get
            {
                return this.panel1;
            }
        }
    }

    internal class MyControlDesigner : ControlDesigner
    {
        public override void Initialize(IComponent component)
        {

            base.Initialize(component);

            MyControl control = component as MyControl;

            EnableDesignMode(control.ContentPanel, "ContentPanel");
        }
    }
}

Update:

I found another related question/answer to this problem of dragging and dropping controls at design time onto a container control within the custom user control:

  1. Question
  2. Referenced Article

I followed the above article and successfully dragged and dropped toolbox controls onto a container control within my custom user control at design time.

  • 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-21T14:13:30+00:00Added an answer on May 21, 2026 at 2:13 pm

    The problem is really pretty simple. You say that you’ve created a UserControl, then added a Panel control to it that is docked to fill the entire UserControl.

    Thus, whenever you add controls to the UserControl at design time, you’re not adding them to the Panel control, but instead the UserControl itself. That causes them to be covered up by the Panel control that fills the entire UserControl.

    Bringing them to the front is a temporary solution, as that places them on top of the Panel control. It does not, however, place them inside the Panel control, which is why they “disappear” again when you rebuild the project. They don’t actually disappear, they just get hidden by the Panel control again, as the default Z order arrangement has them located underneath the Panel.

    It’s not clear why you need the Panel control at all. If it fills the entire UserControl, it doesn’t seem to serve any purpose. A UserControl is already a container control, so you don’t need a Panel. Try removing it from your UserControl, and then you can add whatever other controls you want at design time without them being covered up by the docked Panel.

    If you absolutely have to have a Panel control filling your UserControl, you need to add a line of code that automatically adds the control being dropped onto the UserControl at design time to the Controls collection for the Panel control.

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

Sidebar

Related Questions

I created a user control which contains a ListView with a custom ItemsPanelTemplate. <UserControl
I've created a custom user control that has several properties. One specifies which database
I created a custom DataGridViewCell to show a specific UserControl when the user starts
I have created Custom User Control which contain TextBox and PasswordBox. it is binding
I have a radgrid, for date column i have created a custom user control
I have a custom VB.NET control that I created that is working correctly in
i have created a custom user control which im using on my main xaml
I've created a custom WinForms UserControl and would like to override Dispose. However the
I created a custom password box user control which is able to show and
I created a custom user control which contains an <Image /> control. My user

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.