0

Hello I am creating a windows form application, I am trying to create and add a new Control in this case it is a Panel from a different class, however when I have created the Panel and added it to the form it doesn't appear? [NOTE: I can change the text of the form with F.text("Some text"); but F.Controls.Add(panel1); doesn't work].

Here is my code:

public static void Create(Form1 F)
    {
         //this works:
         F.Text = "DEFAULT TEXT";
         Panel test = new Panel();
         test.Dock = DockStyle.Fill;
         test.BackColor = System.Drawing.Color.Black;
         test.Show();
         //this does not:
         F.Controls.Add(test);
    }
3
  • Settings the .Text property for Form1 does work? Commented Apr 15, 2014 at 6:59
  • In what way does it not work? Commented Apr 15, 2014 at 6:59
  • @FredrikMörk I can set the title of the form with F.text("Some Text"); Commented Apr 15, 2014 at 7:14

2 Answers 2

1

If you are adding the control from other class, Locate the control using Control c = fr.Controls["controlname"];

and then add it to the form that you want. F.controls.add(c);

Sign up to request clarification or add additional context in comments.

Comments

0

This works fine for me

    public Form1(){
 InitializeComponent();
            Create(this);

        }

        public static void Create(Form1 F)
        {
            //this works:
            F.Text = "DEFAULT TEXT";
            Panel test = new Panel();
            test.Dock = DockStyle.Fill;
            test.BackColor = Color.Blue;

            //test.Show(); this is irrelevant
            //this does not:
            F.Controls.Add(test);

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.