Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
555
Dynamic Tab Addition
posted

I have a preexisting UltraTabControl. I want to dynamically add tabs to it and have it initialize to a custom class that inherits from UserControl. Here is how I do it.

 

UltraTabControl m3tc = controlCurrentlyLoaded.TabControl;

M3Control newControl = new CustomUserControl();

newControl.AutoScroll = true;

newControl.BackColor = System.Drawing.SystemColors.ControlLight;

newControl.Dock = System.Windows.Forms.DockStyle.Fill;

newControl.Location = new System.Drawing.Point(0, 0);

newControl.Margin = new System.Windows.Forms.Padding(5);

newControl.Name = "newControl1";

newControl.Size = new System.Drawing.Size(1222, 521);

newControl.TabIndex = 0;

newControl.AutoScroll =
true;

newControl.BackColor = System.Drawing.SystemColors.ControlLight;

newControl.Dock = System.Windows.Forms.DockStyle.Fill;

newControl.Size = new System.Drawing.Size(1222, 521);

UltraTab tabToAdd = new UltraTab();

UltraTabPageControl utpc = new UltraTabPageControl();

utpc.Location = new System.Drawing.Point(-10000, -10000);

utpc.Name = "ultraTabPageControl3";utpc.Size = new System.Drawing.Size(1222, 521);

utpc.Controls.Add(newControl);

tabToAdd.TabPage = utpc;

Infragistics.Win.
Appearance appearance1 = new Infragistics.Win.Appearance();

appearance1.BackColor = System.Drawing.Color.Orange;

appearance1.BackColor2 = System.Drawing.SystemColors.Control;

appearance1.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;

appearance1.FontData.BoldAsString = "True";

m3tc.ActiveTabAppearance = appearance1;

utpc.ResumeLayout(
false);

 

tabToAdd.Key =
"New Tab";tabToAdd.Text = "New";

m3tc.Add(tabToAdd);

 

 

When I run this I get a blank screen on the newly added tab instead of the "newControl" instance (which has some controls on it such as label, textboxes, etc). What am I doing wrong?

Parents
  • 44743
    posted

    I see two issues with the code:

    1. You should probably call SuspendLayout on the tab page control before adding the child controls if you are also going to call ResumeLayout.
    2. The tab page control is never added to the tab control's Controls collection. Add this line after the ResumeLayout call: m3tc.Controls.Add(utpc);
Reply Children