C#自定义控件属性,属性问题。

qianshao 的BLOG
用户名:qianshao
文章数:242
评论数:120
访问量:1038089
注册日期:
阅读量:5863
阅读量:12276
阅读量:301871
阅读量:1020992
51CTO推荐博文
2-16& 用户自定义控件
u本节学习目标:
n了解用户自定义控件的基本类型
n学习如何建立用户自定义控件并引用它
&&& 2-16-1 简介
&&& 2-16-2 用户自定义控件实践操作
1. 案例学习:如何建立用户自定义控件并引用它
650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)' border="0" alt="" src="/attachment/940718.jpg" />
图2-49& 添加用户控件
650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)' border="0" alt="" src="/attachment/135328.jpg" />
图2-50& 拖放一个label标签和一个Button控件
public class UserControl1 : UserControl
public UserControl1()
InitializeComponent();
int i = 0;
private void button1_Click(object sender, EventArgs e)
label1.Text = i.ToString();
650) this.width=650;" onclick='window.open("/viewpic.php?refimg=" + this.src)' border="0" alt="" src="/attachment/160640.jpg" />
图2-51& 建立并使用组件的基本步骤
2-17& 本章小结
nWinform单选按钮控件允许用户进行设置
nWinform的图片框控件允许用户在窗体上添加和显示位图、元文件、JPEG、GIF 或 PNG 等格式的图形
nWinform的选项卡控件将类似的功能集中在一起,放在一个对话框或窗口中
n进度条控件用于指示操作的进度,并显示排列在水平条中一定数目的矩形,通常通过在程序中设置其Value值来显示任务完成的百分比
nTimer 控件为开发人员提供了一种在指定时刻或指定的周期执行任务的控件
nTimer 控件的 Interval 属性表示时钟的周期,单位为毫秒
nListView 控件用于以特定样式或视图类型显示列表项,其Items集合对象提供了对其列表项的操作
nTreeView 控件用于以节点形式显示文本或数据,这些节点按层次结构顺序排列
nTreeView控件的Nodes集合对象提供了对树型节点的操作
课 后 练 习
1、如何使得RadioButton单选按钮组中只选择一个按钮?
2、设计一个ToolBar工具条,加载ImageList 控件里面的图片信息。
3、StatusStrip 控件主要作用是什么?StatusStrip 控件可以加载哪些其他控件在里面呢?
4、通过Timer控件控制一张图片自上而下的循环运动,编写出相关代码。
5、定义用户自定义控件对于项目开发的实际意义是什么?本文出自 “” 博客,转载请与作者联系!
了这篇文章
类别:┆阅读(0)┆评论(0)
11:22:27 11:23:29 11:24:41 22:26:37&&&&&&&&&&&&&&&&&&&&&&&& 12:58:49
&&网站联系: qq: email:&&&&&C# 自定义控件的属性和添加事件
C# 自定义控件的属性和添加事件
C# 自定义控件的属性
添加自定义控件的事件
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
开发技术下载排行& & &刚刚开始程序设计的码农生涯,也许一些开发工具上的控件可以满足我们的需求,但是随之时间的迁移,我们对控件的呈现形式需求越来越多样化,这个时候就需要我们来自定义控件,我是一个刚刚入职没多久的菜鸟,接触软件开发也没有超过两年的时间,在以前的日子里,开发工具上的控件基本可以达到我学习的目的。但是现在工作了,用户的需求多样化,也造就了我们程序员的鬼斧神手。
& & 今天由于需求,我需要作出如下图这样的界面并绑定数据库数据,开始我有几个思路,并且一个一个去尝试,对于winform的这种格式,之前从来也没有做过,如果是asp.net这种格式的话就非常的简单了。
& & 思路一:listview控件,看上去listview控件可以实现这种界面,但是由于界面的局限性,做出这种效果似乎不大可能,在尝试过一两天的时间后,我觉得绑定数据是没有任何问题的,但是,问题就是在listview控件中实现如下图这种格式的布局。所以我选择了放弃,不知道各位用listview控件实现过这种效果没有。后来听说重写listview的方法可行,但是我没有去试过。
& & 思路二:datagridview控件,开始没有往这个方面去考虑,部门里大牛们说可以,我仔细的看了一下datagridview控件的一下属性,其中列的类型里面控件格式没有我需要的控件,可得的话,又要方法重写了。这个工作量估计很大,而且布局能不能布局成这样的效果我也不知道。这个我想了一下也没有去尝试。
& & 思路三:自定义控件,以前在学校里面接触过自定义控件,但都是简单的拼接一下各个不同的控件,没有什么特别的功能,今天特意的学习了一下字典控件,最终做好了一个类似于IDE里面的控件一样可以轻松使用。
& & 实现效果不再熬数,这里我记下我写过的代码:
using System.Dusing System.Data.SqlCnamespace menu{
partial class MyControl
/// &summary&
/// 清理所有正在使用的资源。
/// &/summary&
/// &param name="disposing"&如果应释放托管资源,为 true;否则为 false。&/param&
protected override void Dispose(bool disposing)
if (disposing && (components != null))
components.Dispose();
base.Dispose(disposing);
#region 组件设计器生成的代码
/// &summary&
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// &/summary&
private void InitializeComponent()
ponents = ponentModel.Container();
ponentResourceManager resources = ponentResourceManager(typeof(MyControl));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.imageList1 = new System.Windows.Forms.ponents);
this.groupBox1.SuspendLayout();
((ponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
// groupBox1
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.pictureBox1);
this.groupBox1.Location = new System.Drawing.Point(0, 14);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(99, 163);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop =
this.groupBox1.Text = "groupBox1";
this.label1.AutoSize =
this.label1.Location = new System.Drawing.Point(6, 116);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 12);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
// pictureBox1
this.pictureBox1.Location = new System.Drawing.Point(3, 17);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(90, 90);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop =
this.label2.AutoSize =
this.label2.Location = new System.Drawing.Point(114, 31);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(41, 12);
this.label2.TabIndex = 2;
this.label2.Text = "label2";
this.label3.AutoSize =
this.label3.Location = new System.Drawing.Point(114, 70);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(41, 12);
this.label3.TabIndex = 3;
this.label3.Text = "label3";
this.label4.AutoSize =
this.label4.Location = new System.Drawing.Point(116, 109);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(41, 12);
this.label4.TabIndex = 4;
this.label4.Text = "label4";
this.label5.AutoSize =
this.label5.Location = new System.Drawing.Point(114, 148);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(41, 12);
this.label5.TabIndex = 5;
this.label5.Text = "label5";
// imageList1
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.T
this.imageList1.Images.SetKeyName(0, "001.jpg");
this.imageList1.Images.SetKeyName(1, "002.jpg");
// MyControl
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.F
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label2);
this.Controls.Add(this.label3);
this.Controls.Add(this.groupBox1);
this.Name = "MyControl";
this.Size = new System.Drawing.Size(235, 207);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((ponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
#endregion
System.Windows.Forms.GroupBox groupBox1;
public System.Windows.Forms.Label label1;
public System.Windows.Forms.PictureBox pictureBox1;
public System.Windows.Forms.Label label2;
public System.Windows.Forms.Label label3;
public System.Windows.Forms.Label label4;
public System.Windows.Forms.Label label5;
public void DataLoad(int m)
//自定义数据绑定方法
SqlConnection con = Class1.CyCon();
con.Open();
string str="select * from tb_test where id='"+m+"'";
SqlCommand cmd = new SqlCommand(str, con);
//DataSet ds = new DataSet();
//sda.Fill(ds);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
groupBox1.Text = sdr["id"].ToString();
label1.Text = sdr["position"].ToString();
label2.Text = "工号:"+sdr["workno"].ToString();
label3.Text = "姓名:"+sdr["name"].ToString();
label4.Text = "类型:" + sdr["leixing"].ToString();
label5.Text = sdr["time"].ToString();
if (sdr["leixing"].ToString()=="进")
pictureBox1.Image = imageList1.Images[1];
pictureBox1.Image = imageList1.Images[0];
/*if(label4.Text=="出")
pictureBox1.Image = imageList1.Images[1];
public System.Windows.Forms.ImageList imageList1;
ponentModel.IC
阅读(...) 评论()}

我要回帖

更多关于 自定义控件 集合属性 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信