Creating identical tabs
-
Hi, I'm working on a small app that has a tab panel and I need to create a new tab with a few buttons and text boxes each time a text file is opened. My problem is how to create an identical tab each time with all of the same buttons and boxes with all the same code. Any ideas? Thanks. -NF
-
Hi, I'm working on a small app that has a tab panel and I need to create a new tab with a few buttons and text boxes each time a text file is opened. My problem is how to create an identical tab each time with all of the same buttons and boxes with all the same code. Any ideas? Thanks. -NF
The best way is to extend
TabPage
with your own class and add all your controls and default logic to that class. Whenever you need to add a new tab to yourTabControl
, simply instantiate a new instance of your customTabPage
class and add that toTabControl.TabPages
.Microsoft MVP, Visual C# My Articles
-
The best way is to extend
TabPage
with your own class and add all your controls and default logic to that class. Whenever you need to add a new tab to yourTabControl
, simply instantiate a new instance of your customTabPage
class and add that toTabControl.TabPages
.Microsoft MVP, Visual C# My Articles
Ok thanks for the help, I did what you instructed but the new TabPage will not show up on the form. I looked around for methods that seemed to help update Windows Forms controls. I found SuspendLayout() and ResumeLayout() and also Refresh(). I invoke SuspendLayout on the From, TabControl, and the TabPage before adding the controls to the TabPage, then to the TabControl. Then I do ResumeLayout(false) for all three objects after everything is done. That didn't work so I called Refresh() on everything that I logically could. Still no new tab? I made sure I added the TabPage to the TabControl and everything. Any ideas? Thanks again for your help. -NF
-
The best way is to extend
TabPage
with your own class and add all your controls and default logic to that class. Whenever you need to add a new tab to yourTabControl
, simply instantiate a new instance of your customTabPage
class and add that toTabControl.TabPages
.Microsoft MVP, Visual C# My Articles
Never mind I just had to much code mixed up all over the place, anyway, it works now. Thanks again for your help. -Noah Fields