C# 如何在继承的WinForm中向容器添加控件
我在另一个项目中有一个基本表单,它对我们所有的WinForms程序强制执行相同的外观。我继承了BaseForm,创建了自己的模板BaseView。我的这个模板有额外的控件,比如ProgressBar、计时器和TableLayoutPanel 现在我想从BaseView继承并使用设计器添加程序特定的控件,但是我不能将任何类似于面板或任何其他控件的内容放入其中。我尝试了一些建议,比如确保基本表单的组件是公共的,但是没有用——TLP的大多数属性仍然是灰色的 有人能给我一些建议吗?非常感谢C# 如何在继承的WinForm中向容器添加控件,c#,winforms,panel,designer,C#,Winforms,Panel,Designer,我在另一个项目中有一个基本表单,它对我们所有的WinForms程序强制执行相同的外观。我继承了BaseForm,创建了自己的模板BaseView。我的这个模板有额外的控件,比如ProgressBar、计时器和TableLayoutPanel 现在我想从BaseView继承并使用设计器添加程序特定的控件,但是我不能将任何类似于面板或任何其他控件的内容放入其中。我尝试了一些建议,比如确保基本表单的组件是公共的,但是没有用——TLP的大多数属性仍然是灰色的 有人能给我一些建议吗?非常感谢 部分类基本
部分类基本视图
{
///
///必需的设计器变量。
///
private System.ComponentModel.IContainer components=null;
///
///清理所有正在使用的资源。
///
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
///
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
///
私有void InitializeComponent()
{
this.components=new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager资源=新的System.ComponentModel.ComponentResourceManager(typeof(BaseView));
this.tableLayoutPanel_Form=new System.Windows.Forms.tableLayoutPanel();
this.panel_Buttons=new System.Windows.Forms.panel();
this.panel_MainBody=new System.Windows.Forms.panel();
this.progressBar=new System.Windows.Forms.progressBar();
this.timer\u ProgressBar=新的System.Windows.Forms.timer(this.components);
此.tableLayoutPanel_Form.SuspendLayout();
这个.SuspendLayout();
//
//lblFormId
//
this.lblFormId.AutoSize=false;
this.lblFormId.Location=新系统图纸点(390,9);
this.lblFormId.Size=新系统图纸尺寸(98,13);
this.lblFormId.TextAlign=System.Drawing.ContentAlignment.MiddleRight;
//
//btnClose
//
this.btnClose.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right));
this.btnClose.DialogResult=System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Location=新系统.Drawing.Point(447,5);
this.btnClose.Size=新系统.Drawing.Size(41,21);
this.btnClose.TabIndex=4;
//
//tableLayoutPanel_表单
//
this.tableLayoutPanel_Form.ColumnCount=1;
this.tableLayoutPanel_Form.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,100F));
this.tableLayoutPanel\u Form.Controls.Add(this.panel\u按钮,0,2);
this.tableLayoutPanel\u Form.Controls.Add(this.panel\u主体,0,1);
this.tableLayoutPanel_Form.Dock=System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel_Form.Location=新系统.Drawing.Point(0,0);
this.tableLayoutPanel\u Form.Name=“tableLayoutPanel\u Form”;
this.tableLayoutPanel_Form.RowCount=3;
this.tableLayoutPanel_Form.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute,30F));
this.tableLayoutPanel_Form.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent,100F));
this.tableLayoutPanel_Form.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute,30F));
this.tableLayoutPanel_Form.Size=新系统图尺寸(496322);
this.tableLayoutPanel_Form.TabIndex=26;
//
//面板按钮
//
this.panel_Buttons.Dock=System.Windows.Forms.DockStyle.Fill;
this.panel_Buttons.Location=新系统图点(3295);
this.panel\u Buttons.Name=“panel\u Buttons”;
this.panel_Buttons.Size=新系统图纸尺寸(490,24);
this.panel_Buttons.TabIndex=0;
//
//面板主体
//
this.panel_MainBody.Dock=System.Windows.Forms.DockStyle.Fill;
this.panel_MainBody.Location=新系统图纸点(3,33);
this.panel\u MainBody.Name=“panel\u MainBody”;
this.panel_MainBody.Size=新系统图尺寸(490256);
this.panel_MainBody.TabIndex=1;
//
//进度条
//
this.progressBar.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right));
this.progressBar.Location=新系统图点(383324);
this.progressBar.Name=“progressBar”;
this.progressBar.Size=新系统图纸尺寸(112,21);
this.progressBar.TabIndex=27;
//
//计时器进度条
//
this.timer_ProgressBar.Interval=700;
this.timer\u ProgressBar.Tick+=新的System.EventHandler(this.timer\u Tick);
//
//BaseView
//
此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
this.CancelButton=this.btnClose;
this.ClientSize=新系统.Drawing.Size(496346);
this.Controls.Add(this.progressBar);
this.Controls.Add(this.tableLayoutPanel_表单);
this.Cursor=System.Windows.Forms.Cursors.Default;
this.Icon=((System.Drawing.Icon)(resources.GetObject($this.Icon));
this.MinimumSize=新系统图纸尺寸(512,384);
this.Name=“BaseView”;
this.Controls.SetChildIndex(this.btnClose,0);
this.Controls.SetChildIndex(this.tabella
partial class BaseView
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BaseView));
this.tableLayoutPanel_Form = new System.Windows.Forms.TableLayoutPanel();
this.panel_Buttons = new System.Windows.Forms.Panel();
this.panel_MainBody = new System.Windows.Forms.Panel();
this.progressBar = new System.Windows.Forms.ProgressBar();
this.timer_ProgressBar = new System.Windows.Forms.Timer(this.components);
this.tableLayoutPanel_Form.SuspendLayout();
this.SuspendLayout();
//
// lblFormId
//
this.lblFormId.AutoSize = false;
this.lblFormId.Location = new System.Drawing.Point(390, 9);
this.lblFormId.Size = new System.Drawing.Size(98, 13);
this.lblFormId.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// btnClose
//
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Location = new System.Drawing.Point(447, 5);
this.btnClose.Size = new System.Drawing.Size(41, 21);
this.btnClose.TabIndex = 4;
//
// tableLayoutPanel_Form
//
this.tableLayoutPanel_Form.ColumnCount = 1;
this.tableLayoutPanel_Form.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel_Form.Controls.Add(this.panel_Buttons, 0, 2);
this.tableLayoutPanel_Form.Controls.Add(this.panel_MainBody, 0, 1);
this.tableLayoutPanel_Form.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel_Form.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel_Form.Name = "tableLayoutPanel_Form";
this.tableLayoutPanel_Form.RowCount = 3;
this.tableLayoutPanel_Form.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel_Form.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel_Form.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel_Form.Size = new System.Drawing.Size(496, 322);
this.tableLayoutPanel_Form.TabIndex = 26;
//
// panel_Buttons
//
this.panel_Buttons.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel_Buttons.Location = new System.Drawing.Point(3, 295);
this.panel_Buttons.Name = "panel_Buttons";
this.panel_Buttons.Size = new System.Drawing.Size(490, 24);
this.panel_Buttons.TabIndex = 0;
//
// panel_MainBody
//
this.panel_MainBody.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel_MainBody.Location = new System.Drawing.Point(3, 33);
this.panel_MainBody.Name = "panel_MainBody";
this.panel_MainBody.Size = new System.Drawing.Size(490, 256);
this.panel_MainBody.TabIndex = 1;
//
// progressBar
//
this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.progressBar.Location = new System.Drawing.Point(383, 324);
this.progressBar.Name = "progressBar";
this.progressBar.Size = new System.Drawing.Size(112, 21);
this.progressBar.TabIndex = 27;
//
// timer_ProgressBar
//
this.timer_ProgressBar.Interval = 700;
this.timer_ProgressBar.Tick += new System.EventHandler(this.timer_Tick);
//
// BaseView
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.CancelButton = this.btnClose;
this.ClientSize = new System.Drawing.Size(496, 346);
this.Controls.Add(this.progressBar);
this.Controls.Add(this.tableLayoutPanel_Form);
this.Cursor = System.Windows.Forms.Cursors.Default;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(512, 384);
this.Name = "BaseView";
this.Controls.SetChildIndex(this.btnClose, 0);
this.Controls.SetChildIndex(this.tableLayoutPanel_Form, 0);
this.Controls.SetChildIndex(this.lblFormId, 0);
this.Controls.SetChildIndex(this.lblFormDescription, 0);
this.Controls.SetChildIndex(this.progressBar, 0);
this.tableLayoutPanel_Form.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ProgressBar progressBar;
private System.Windows.Forms.Timer timer_ProgressBar;
public System.Windows.Forms.TableLayoutPanel tableLayoutPanel_Form;
public System.Windows.Forms.Panel panel_Buttons;
public System.Windows.Forms.Panel panel_MainBody;
}