简体   繁体   English

将Visual Studio Windows窗体设计器用于非窗体(如面板或otner)

[英]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.

相关问题 Visual Studio Windows Forms 设计器错误 - Visual Studio Windows Forms Designer Error Visual Studio 中未显示设计器视图 windows forms - Designer view not showing in Visual Studio windows forms Visual Studio形成设计师 - Visual Studio forms designer 如何让 Visual Studio 2008 Windows 窗体设计器呈现实现抽象基类的窗体? - How can I get Visual Studio 2008 Windows Forms designer to render a Form that implements an abstract base class? Visual Studio 2017:Windows 窗体设计器未出现 - Visual Studio 2017 : Windows Form designer not appear 创建使您可以从Visual Studio Forms Designer中选择当前表单中其他控件的下拉菜单 - Create dropdowns that let you select other controls in the current form from the Visual Studio Forms Designer 在Visual Studio中扩展FlowLayoutPanel,以便可以将其添加到设计器中的其他表单吗? - Extending FlowLayoutPanel in Visual Studio so it can be added to other forms in the designer? 无法使用带有 Visual Studio 2010 的 Windows 窗体获取设计器视图窗口 - Unable to get the designer view window back using windows forms with Visual Studio 2010 如何重新同步Visual Studio 2008 Windows窗体设计器? - How do I resync the Visual Studio 2008 Windows Forms Designer? 使用Visual Studio Designer将Table窗体控件置于TableLayoutPanel中 - Centering Windows Forms Controls inside TableLayoutPanel with Visual Studio Designer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM