locked
Dynamically create & add controls to a container control... RRS feed

  • Question

  • Hi...

            In my application, I have to add many controls at run time & fill the properties of that controls through some custom classes. I am having a tab control inside that each tab page of that tab control i have added a Panel control(Say 'mainPanel' - Dock property of this Panel is 'Fill'). This much i did at design time. Now i am having some custom classes which actually contains properties of the of C# controls(like label, comboboc, textbox etc.).

            These are my custom classes for those control's properties. 
                For Label Control ->  CCustomLabel
                For TextBox Control ->  CCustomTextBox
                For ComboBox Control ->  CCustomCombobox

            Each of these classes will have properties like Location, Size, Text etc. I am filling these class properties by reading XML file. 
    Now dynamically i have to use these objects & create all the controls dynamically. Some of this controls i have to group & attach to a child panel (ChildPanel will be inside the mainPanel & there can be more than one child panel inside one mainPanel of a tabPage). 

            I am not able to attach these custom controls to its Parent container at run time. I mean i am doing like this...

                childPanel.Controls.Add(objCustomeLabel1);
                childPanel.Controls.Add(objCustomeLabel2);
                childPanel.Controls.Add(objCustomeTextBox1);
                childPanel.Controls.Add(objCustomeCombobox1);

            And then...
                 mainPanel.Controls.Add(childPanel);

            Its not throwing any excpetion but i am not able to see any controls in my GUI when i run my application.

            
            What else i have to do to make my controls visible...???

    Thanks in adavance,
    IamHuM

        
    Thursday, June 26, 2008 3:15 AM

Answers

  • if u can provide some code then might help u.
    one solution is try using BringToFront() method on controls which u add to container

    Wife is like a Software, Lots of bugs.
    • Marked as answer by jack 321 Tuesday, July 1, 2008 2:55 AM
    Friday, June 27, 2008 11:57 AM
  •   What else i have to do to make my controls visible...???

    First you should do something in debugger. You should walk thru the loop that adds the CustomLabel and such and see if the controls are really added. It is very easy.

    Next, if everything is correct, then do .Refresh ( ) on your Panel (I mean your parent control). This may be your major problem, actually.

    AlexB
    • Marked as answer by jack 321 Tuesday, July 1, 2008 2:55 AM
    Friday, June 27, 2008 1:25 PM

All replies

  • Controls that you create in runtime have their Visible property set to false. So, when adding your controls to the control collections you need to set Visible=true.

    /Calle

    • Proposed as answer by Calle Mellergardh Thursday, June 26, 2008 7:01 AM
    • Marked as answer by jack 321 Monday, June 30, 2008 3:17 AM
    Thursday, June 26, 2008 7:01 AM
  • if u can provide some code then might help u.
    one solution is try using BringToFront() method on controls which u add to container

    Wife is like a Software, Lots of bugs.
    • Marked as answer by jack 321 Tuesday, July 1, 2008 2:55 AM
    Friday, June 27, 2008 11:57 AM
  •   What else i have to do to make my controls visible...???

    First you should do something in debugger. You should walk thru the loop that adds the CustomLabel and such and see if the controls are really added. It is very easy.

    Next, if everything is correct, then do .Refresh ( ) on your Panel (I mean your parent control). This may be your major problem, actually.

    AlexB
    • Marked as answer by jack 321 Tuesday, July 1, 2008 2:55 AM
    Friday, June 27, 2008 1:25 PM
  • if u provide some code snippet, then might help u.
    One solution could be try calling BringToFront() method of child controls

    Wife is like a Software, Lots of bugs.
    • Marked as answer by jack 321 Monday, June 30, 2008 3:17 AM
    Saturday, June 28, 2008 12:18 PM