Click here to Skip to main content
15,900,664 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello everyone,

I have a problem. I've been searching google all day with no luck trying to find out how do I create an inherited tab control that initially has no tab pages. Here's what I mean: the control is being designed in a way that the programmer has to call a built in method with a parameter, and that method will fill out the tabpage accordingly. Right now, tabcontrol has this annoying feature that when I drag and drop the control on a form, it automatically generates the following in the form designer:

VB
'
'MyControl
'
Me.MyControl.Controls.Add(Me.TabPage1)
Me.MyControl.Controls.Add(Me.TabPage2)
Me.MyControl.Location = New System.Drawing.Point(0, 0)
Me.MyControl.Name = "MyControl"
Me.MyControl.SelectedIndex = 0
Me.MyControl.Size = New System.Drawing.Size(496, 462)
Me.MyControl.TabIndex = 0
'
'TabPage1
'
Me.TabPage1.Location = New System.Drawing.Point(4, 22)
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage1.Size = New System.Drawing.Size(488, 436)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "TabPage1"
Me.TabPage1.UseVisualStyleBackColor = True
'
'TabPage2
'
Me.TabPage2.Location = New System.Drawing.Point(4, 22)
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage2.Size = New System.Drawing.Size(488, 436)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "TabPage2"
Me.TabPage2.UseVisualStyleBackColor = True


Which is totally useless to me... I want to prevent the above code from being generated whenever I drag and drop my control... Please help!
Posted
Comments
Sergey Alexandrovich Kryukov 30-Jul-12 17:21pm    
Well, don't code in spaghetti style... :-) What's the problem? If you don't need this code, don't have it.
--SA
SpaghettiCoder 31-Jul-12 8:52am    
:P

Edit the TabPages property and delete the pages.
 
Share this answer
 
Who forces you to use the Designer? Add an empty TabControl, and don't add anything to it. Remove all code creating a tab page, so you would start with zero tab pages during run-time. By the way, if you are confused about using of this control, the auto-generated code is not useless to you: you can look at it to understand how to add tabs in your code.

—SA
 
Share this answer
 
Comments
SpaghettiCoder 31-Jul-12 8:59am    
I was looking for something along the lines of using
designerserializationvisibility ( blah.blah ) Public Property Foo() As TabCollection, but that doesn't seem to work. Here's the deal, I'm creating an inherited control based on the tabcontrol. In order to save time not having to perform a page deletion everytime I add the control to the form, I want the control never to auto generate the two default tabpages, since I'm generating my own default tabpages with dynamic content.
Sergey Alexandrovich Kryukov 31-Jul-12 11:39am    
Look, I've used TabControl many times, never had any problems. You are missing something. Why would adding your control to its parent should delete any pages? If you don't need pages, don't add them. Not, don't you thing you are taking Designer too serious? Do you provide your control as a library for other developers? If not, why using Designer at all? It is not for serious UI development, mostly for quick and dirty form mish-mash...
--SA
SpaghettiCoder 31-Jul-12 15:45pm    
You hit the nail on the head sir, I intend to provide the control within a library for my team of developers, which is why I want it to work in such a way... Don't tell me that you think that a Spaghetti Coder is a perfectionist too ;)

Sergey Alexandrovich Kryukov 31-Jul-12 17:19pm    
"Spaghetti coding" and perfectionism are nearly mutually exclusive, but I still can imagine a perfectionist spaghetti coder. :-)
If you think that your fellow developers would need using your control through the designer, you probably need to smooth it out. And of course, the collection of pages allows to remove a page, so what's a problem?
Unfortunately, you did not share exact type you imply under the name TabControl. There are more than one class under this name. So, how about a full name? (WPF, Forms).
--SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900