• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

I need separate instances for each tab. I have a Tab Control that will add tabs during runtime, and I want each tab to have all the controls as the original

I'm using a tab system that adds a tab every time a user clicks a button, and with that tab the same controls need to come up on each tab.  These controls have to be named the same and access the same databases, so I want it to copy the first instance to a new tab every time a new tab is added.

This program is used to take calls.  A person calls in and the user takes down their information on the first tab.  Then another person calls in, and the user needs to take their information down, so I add another tab with all the same controls on it.

How do I copy all the controls over to the new tab with empty fields, or Open up a bunch of saved controls that access the same database tables.

Can you help?
  • 2
1 Solution
Make a custom control and use visual inheritance. You can do this by creating a new Windows Control Library ... Compile that and then in your main project add a reference to that dll and you will see your control in the toolbox. If you know this already then I apologize. If not you will also want to take care of the event handling for those controls too. This is one way to do it.
RAMCITAuthor Commented:
How would you make a new Windows Control Library?  How woudl you take care of the event handling?
Well you create a new project and instead of creating a Windows Application you create a Windows Control library. There you have what looks like a "borderless form" but is really just space for you to add your controls. So this is like a way you  extend "built-in" controls. Like you can make a custom login box control, or a control does color mixing (like if you take 3 track bars to represent RGB, and then make a label with a backcolor property, you have made your own control to use in your applications).

So what you do is create your control, put all the code necessary for the immediate control. Since it is your control you can go ahead and program the middle-tier stuff right into the control if you want, like accessing your database.

Ok, and once you do that you need to think about how you want to use that control in your application. Maybe you want a Public Property (which would actually show up in the "Properties" window, like for any other control). Then you need to think about if you want your application to listen for events from that control. Actually it is possible that you could decide that you don't need to listen to any events from that control, if the control has the middle tier stuff coded into it (updating your DB and stuff).

So yes, I guess in your case you may not need events but if you do you want to look up delegates and "raising events" especially from UserControl (that is a custom control class).

This is a way for you to just drag and drop this control on any form you want, or whatever, without "copying" or any of this other business. It works very well. One thing to remember is assign your control a name when you make it, and change the "Class name" in the code view. Otherwise you will have the control being called "UserControl" in your toolbox.

Well, just try it out and I think it will make sense. This seems like the best way to solve your problem. Hope this helps.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now