[英]Using Visual Studio Windows Form Designer for other than Forms (like panels or otner)
I'm relatively new to c# and Visual Studio. 我是C#和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. 在我的应用程序中,我有一个TabControl,并且用户可以创建任意数量的TabPage。当用户添加页面时,我的程序自动在此页面内创建大量控件,其中包含我自己编写的许多行。
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 ? 我的问题是:有没有一种方法可以在设计时使用Form Designer创建TabPage(就像我对表单所做的那样),以便代码自动生成? And then use this "prefrabbicated" component (my TabPage) with a line like this?
然后使用像这样的一行使用这个“ prefrabbicated”组件(我的TabPage)?
pag1 = new myCustom_TabPage(...) ?
I tried to create a class of type TabPage like this 我试图创建这样的TabPage类型的类
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 但是当我按Shift + F7调用Designer时,它显示空白屏幕,而当我将某些组件放入其中时,它并不能真正直观地显示我可以调整ecc的大小,而每个组件只能调整一个块,例如表单设计器中的组件),您可以单击和编辑属性,仅此而已
Thanks, Luca. 谢谢,卢卡
Yep! 是的 Excuse my VB, make a class that inherits from TabPage:
对不起,我的VB创建了一个从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: 然后修改设计器文件,用新类替换旧的TabPage之一:
<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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.