4

Hey so first off i would like to point out that I know that there are several other questions about this topic up here, I have even done this exact thing myself before. I am asking on here because I do not know what my problem is.

Here is the code where I attempt to display the new user control

private void ValidationLabel_Click(object sender, EventArgs e)
    {
        EntrySuggestion t_ES = new EntrySuggestion();
        t_ES.Show();
        MainScreen home = new MainScreen();
        home.Show();
    }

I was trying to get the t_ES to display (which it does not) but the main Screen does. Both of these are User Controls.

Here is the code for my EntrySuggestion User control

 using System;
using System.Collections;
using System.Windows.Forms;

namespace TeamManagementSystem
{
    public partial class EntrySuggestion : UserControl
    {
        private ArrayList items = new ArrayList();

        public EntrySuggestion()
        {
            InitializeComponent();
        }

        public EntrySuggestion(ArrayList i)
        {
            InitializeComponent();
            items = (ArrayList)i.Clone();
        }

        private void EntrySuggestion_Load(object sender, EventArgs e)
        {
            foreach (string item in items)
            {
                RadioButton t_RB = new RadioButton();
                t_RB.Text = item;
                ItemSuggestionTable.Controls.Add(t_RB);
            }
        }
    }
}

I do want to use the second constructor but I cannot get this to work with either. Any help would be great

6
  • 6
    Is MainScreen derived from a Form? You cannot simply display floating UserControl, they need to be anchored to something. Commented Jul 8, 2013 at 15:25
  • I'm trying to remember...when you add controls to a Windows form (in your case, your t_RB radio buttons), do you need to explicitly set their visibility to have them show up? Commented Jul 8, 2013 at 15:26
  • Have you checked its bounds to see if they are on screen? And has it been added to the form controls? Commented Jul 8, 2013 at 15:26
  • Main Screen is actually a Form, i do not remember doing this. What is the difference between a form and a UserControl? is there no other way to display a popup usercontrol? Commented Jul 8, 2013 at 15:27
  • 4
    @lamilambkin - Add the control to a form, and show the form. Commented Jul 8, 2013 at 15:28

2 Answers 2

10

You need to add your user control to the display surface of the main form (or another container already present)

    MainScreen home = new MainScreen();
    home.Show();
    EntrySuggestion t_ES = new EntrySuggestion();
    home.Controls.Add(t_ES);
Sign up to request clarification or add additional context in comments.

Comments

2

Add your user control to the form:

home.Controls.Add(t_ES);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.