继承并扩展的控件,在设计时如何可见

haiyangshao 2008-11-11 02:32:21
我的一个用户窗体上需要显示非常多的用户数据,每次编程时改动起来非常麻烦,所以决定将其中的一个TabControl多页容器控件及其上面显示的所有子控件,单独封装成一个WINDOWS控件。



编写了一个继承TabControl的类,在上面添加了InitializeComponent()方法,并添加了其它子控件, 试图让其在设计时可见,但一直无法让这个类在设计时象一般的Form窗体一样可见。

是不是因为这个控件不象Form窗体一样有个AutoScaleDimensions属性才无法显示出来。

有没有什么办法让它在设计时,象Form窗体一样,提供一个可视化格式。



当然,如果我先添加一个UserControl类,然后再将TabControl对象及其子控件往上面添加,也还是可以在设计时显示出来的,但是这个控件就不是从TabControl类继承了,其它设计人员使用这个控件时,访问的对象成员方法和习惯都必须改变,太麻烦。



举个简单的例子

/************************************************************************************

为了继承TabControl控件,先写入一个 myTabControl.cs 文件,内容如下

***********************************************************************************/

using System.Windows.Forms;

namespace WindowsFormsApplication1
{

public partial class myTabControl:TabControl
{
public myTabControl()
{
InitializeComponent();
}
}

}



/*****************************************************************

再编写另一个 myTabControl.Designer.cs 文件,内容如下

*****************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{

partial class myTabControl
{
private System.ComponentModel.IContainer components = null;

protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

private void InitializeComponent()
{
this.tabPage1 = new System.Windows.Forms.TabPage();
this.textBox1 = new System.Windows.Forms.TextBox();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.button1 = new System.Windows.Forms.Button();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// tabPage1
//
this.tabPage1.Controls.Add(this.textBox1);
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(399, 218);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(19, 48);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 21);
this.textBox1.TabIndex = 1;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.button1);
this.tabPage2.Location = new System.Drawing.Point(4, 21);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(192, 75);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Location = new System.Drawing.Point(19, 19);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(100, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// myTabControl
//
this.Controls.Add(this.tabPage1);
this.Controls.Add(this.tabPage2);
this.Name = "myTabControl";
this.Size = new System.Drawing.Size(407, 243);
this.tabPage1.ResumeLayout(false);
this.tabPage1.PerformLayout();
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);

}

private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TabPage tabPage2;
}
}




在VS的方案管理器中,双击打开myTabControl.cs 文件,没有见到TabControl控件的界面,只见到一个TextBox和一个Button控件的显示图标。

没有见到一个可视化的设计器。

哪位精通.Net 控件设计的给予指导一下!

...全文
97 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
haiyangshao 2008-11-12
  • 打赏
  • 举报
回复
自己顶一下, CSDN上也没有 .NET控件高手吗?
haiyangshao 2008-11-12
  • 打赏
  • 举报
回复
可问题是, 它在设计时, 没有工作区可以重写
ireenter 2008-11-12
  • 打赏
  • 举报
回复
重写它的OnPaint方法
haiyangshao 2008-11-11
  • 打赏
  • 举报
回复
在微软中文技术论坛上, 问了快1个月了, 都没有结果
连他们的版主也不是很清楚
yilanwuyu123 2008-11-11
  • 打赏
  • 举报
回复
MSDN

8,834

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 组件/控件开发
社区管理员
  • 组件/控件开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧