TabControl Issue

J

Jeff

I am inserting new TabPages to a TabControl, and I'm
having problems with the TabPage's contents not being
shown. I put two pages on the TabControl in the
constructor, and I have a button on the form that inserts
new TabPages. I am wanting to insert the new tab right
before the last tab. Here is the code:

//-----------------------------------------------------
TabPage all = tabControl1.TabPages
[tabControl1.TabPages.Count-1] ;
TabPage page = new TabPage
("Tab "+tabControl1.TabPages.Count-1) ;

bool selectLast = (tabControl1.TabPages.Count-1) ==
tabControl1.SelectedIndex ;

myusercontrol cont = new myusercontrol() ;
page.Controls.Add(i) ;
tabControl1.TabPages[tabControl1.TabPages.Count-1] = page ;
tabControl1.TabPages.Add(all) ;

if (selectLast)
tabControl1.SelectedIndex = tabControl1.TabPages.Count-1 ;
//-----------------------------------------------------

This code inserts the new TabPages appropriately, but the
contents of the new tabs aren't being shown. I tried to
capture the paint event of a button that is
on "myusercontrol", and it isn't firing. If I just add
the new tabs to the end (which I don't want to do) the
button is shown and the paint event fires.

Any clues?
 
J

Jeff

I found out what the problem was. A new tab will not
paint unless TabControl.TagPages.Add(newpage) has been
called for the tab.

Instead of replacing the last tab, I call the Add()
function to add it to the TabPageCollection, then I can
change their position in the array.

I'm not sure why this happens, as I would expect any
tabpage in the collection to paint regardless of how it
was put in the collection. Anyhow, that was the solution
to the problems I was having..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top