Using Visual Studio Windows Form Designer for other than Forms (like panels or otner)
Using Visual Studio Windows Form Designer for other than Forms (like panels or otner)
I'm relatively new to c# and Visual Studio.
In my application I have a TabControl and the user is able to create as many TabPages as he whants, when the user add a page, my program automaticaly create a large quantity of controls inside this page with many and many lines writed by myself.
My question is: Is there a way to create my TabPage at Design Time with Form Designer (as I can do with the forms) so that the code is autogenerated ? And then use this "prefrabbicated" component (my TabPage) with a line like this?
pag1 = new myCustom_TabPage(...) ?
I tried to create a class of type TabPage like this
public class Vista_Tabulato_Pagina : TabPage
{
public Vista_Tabulato_Pagina(VISTE vista)
{
}
private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);
}
}
but when I hit Shift+F7 to invoke the Designer It show a blank screen and when I put some component inside it will not show realy visually that I can resize ecc but only a block for every components, (like when you put a non visual component inside a form designer) you can click and edit properties but thats all
Thanks,
Luca.
TabPage
That doesn't work, the designer for TabPage is rolled up in the designer for TabControl and it only knows about TabPage. Most practical approach is to design a UserControl for each tab page.
– Hans Passant
2 days ago
@AleksAndreev I tried, I created a class inheridet from TabPage and when I hit Shift+F7 to invoke the Designer It show a blank screen and when I put some component inside it will not show realy visually that I can resize ecc but only a block for every components, (like when you put a non visual component inside a form designer) you can click and edit properties but thats all
– Luca Arniani
2 days ago
@HansPassant thanks but what do you mean when you say "design a UserControl" ?
– Luca Arniani
2 days ago
Add a control to your project instead of a form, it should inherit from
UserControl
instead of Form
. It will have a designer. A user control can be added to a tabpage just like any other control.– Lasse Vågsæther Karlsen
2 days ago
UserControl
Form
1 Answer
1
Yep! Excuse my VB, make a class that inherits from TabPage:
Public Class chicken
Inherits TabPage
Sub New()
Me.Controls.Add(New TextBox With {.Text = "Im a textbox!"})
End Sub
End Class
Then hack the designer file, replacing one of the old TabPages with your new class:
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.TabControl1 = New System.Windows.Forms.TabControl
Me.TabPage1 = New System.Windows.Forms.TabPage
Me.TabPage2 = New System.Windows.Forms.TabPage
Me.TabPage3 = New chicken
… etc
Then after a rebuild it'll appear on the designer, and more can be added by using just:
Me.TabControl1.Controls.Add(New chicken)
Thanks, but I'm new to C# and I've some limitation about this, moreover if you write in VB I can't realy understand.... sorry :-(
– Luca Arniani
2 days ago
Do you want me to translate it for you? Or are you willing to translate it yourself? The technique has been written in ENGLISH with the code being an example. You have been shown the solution, the rest is up to you. -.-
– Davesoft
2 days ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You can create a new class and inherit it from
TabPage
. Visual Designer should be available– Aleks Andreev
2 days ago