How to load usercontrl into panel dynamically

2 posts, 0 answers
  1. Dao
    Dao avatar
    13 posts
    Member since:
    Oct 2008

    Posted 11 Aug 2009 Link to this post

    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.
  2. Robert
    Robert avatar
    82 posts
    Member since:
    Jun 2009

    Posted 12 Aug 2009 Link to this post

    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


  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top