This is a migrated thread and some comments may be shown as answers.

How to load usercontrl into panel dynamically

1 Answer 306 Views
Panel
This is a migrated thread and some comments may be shown as answers.
Dao
Top achievements
Rank 1
Dao asked on 12 Aug 2009, 03:27 AM
dear all,
i am newbie in winform.
I have 2 radpanel in mainform. i have 2 usercontrol is usercontrol1,and usercontrol2.
In usercontrol1 have a button. usercontrol1 nested in radpanel1. when app run i want click button in usercontrol1 i wish panel2 load usercontrol2.
how i can archive
thanks all.

1 Answer, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 12 Aug 2009, 06:46 PM
Hey Dao,

You will need to expose your RadButton as a property on UserControl1. Then subscribe to the click event on that button in your main form that contains UserControl1. Once clicked you will need to create UserControl2 then add it to the controls collection on the RadPanel.

    public partial class UserControl1 : UserControl 
    { 
        public UserControl1() 
        { 
            InitializeComponent(); 
        } 
 
        public RadButton Button 
        { 
            get { return radButton1; } 
        } 
    } 

    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
 
            userControl1.Button.Click += new EventHandler(Button_Click); 
        } 
 
        void Button_Click(object sender, EventArgs e) 
        { 
            UserControl2 control2 = new UserControl2(); 
            control2.Dock = DockStyle.Fill; 
            radPanel2.Controls.Add(control2); 
        } 
    } 
I hope this helps.

- Robert


Tags
Panel
Asked by
Dao
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Share this question
or