0

I have a TabControl which contains some tabs. each tab includes a Word component control which loads Microsoft office word. Every time User opens a new tab, a new Word component control has to be add to it which takes a little time. Is there a way to move the current Word component control to the new tab programmatically when adding new tabs, so it doesn't have to create a new component class?

Something like this (But Tabs[1] has no Controls)

stcWordTab.Tabs[1].Controls.Add(stcWordTab.Tabs[0].Controls[0])

EDIT

I'm using DotNetBar's SuperTabItem control.

Ghasem
  • 14,455
  • 21
  • 138
  • 171
  • You realize that when you __move__ it it will no longer be where it was before?! – TaW Dec 18 '14 at 17:01
  • @TaW Yes! that's exactly what i'm planning to do – Ghasem Dec 19 '14 at 20:41
  • I don't know aboput DotNetBar's SuperTabItem. - In winforms I would advise: Please always diferentiate between the Tab Control and its TabPages! If a control, say a Button button1 sits on tabPage1 you can move it to tabPage2 like this: `button1.Parent = tabpage2;` Not sure if your library works the same way, though! – TaW Dec 19 '14 at 22:12

1 Answers1

0

While Tab itself does not has Controls property, it has TabItem.AttachedControl property which is TabControlPanel connected to the tab and this panel hosts your controls.

So your code could looks like

(stcWordTab.Tabs[1].AttachedControl as TabControlPanel).Controls
    .Add((stcWordTab.Tabs[0].AttachedControl as TabControlPanel).Controls[0]);

See knowledge base for reference.

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
  • It completely removes the first tab somehow and deletes the word component as well! – Ghasem Dec 20 '14 at 09:29
  • Hmm... I hav no dotnetbar components installed here right now - so i can't verify it - but here is some suggestions: try to remove controls from `Tabs[0].AttachedControl` before adding it to `Tabs[1].AttachedControl`. And probably you should call `RecalcLayout` method of tabcontrol after moving controls from tab to tab. – Andrey Korneyev Dec 22 '14 at 07:52