【WinForm窗体控件开发】之三续 窗体控件设计时的事件属性
来源:互联网 发布:阿里旺旺 淘宝版 下载 编辑:程序博客网 时间:2024/05/22 03:39
转自:http://www.cnblogs.com/bobbychencj/archive/2010/12/01/1893361.html
这次我们主要将上回自定义控件的Attribute部分如何定义Event事件属性简单说明下:
在自定义的控件中添加自定义的事件属性步骤:
1.需要声明自定义事件参数,一般是继承自EventArgs类;
2.声明事件委托;
3.定义事件名称;
下面我们来看看一个自定义事件的示例:
我们首先定义一个窗体控件【SecondControl自定义控件的Event属性.cs】,代码如下:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WinFormControlLibrary{ public partial class SecondControl自定义控件的Event属性 : TextBox { /// <summary> /// Constructor /// </summary> public SecondControl自定义控件的Event属性() { InitializeComponent(); } /// <summary> /// 声明CustomerLogin自定义事件参数 /// </summary> public sealed class CustomerLoginEventArgs : EventArgs { } /// <summary> /// 声明CustomerLogout自定义事件参数 /// </summary> public sealed class CustomerLogoutEventArgs : EventArgs { } /// <summary> /// 声明CustomerLogin事件委托 /// </summary> public delegate void CustomerLoginEventHandler(object sender, CustomerLoginEventArgs e); /// <summary> /// 声明CustomerLogout事件委托 /// </summary> public delegate void CustomerLogoutEventHandler(object sender, CustomerLogoutEventArgs e); /// <summary> /// 声明事件名称 /// </summary> [CategoryAttribute("自定义事件")] public event CustomerLoginEventHandler CustomerLogin { add { } remove { } } /// <summary> /// 声明事件名称 /// </summary> [CategoryAttribute("自定义事件")] public event CustomerLogoutEventHandler CustomerLogout { add { } remove { } } protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); } }}
接下来,新建Form并添加这个自定义控件,代码如下:
namespace 自定义窗体控件Demo{ partial class 之三窗体控件设计时Event属性Attribute { /// <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.secondControl自定义控件的Event属性1 = new WinFormControlLibrary.SecondControl自定义控件的Event属性(); this.SuspendLayout(); // // secondControl自定义控件的Event属性1 // this.secondControl自定义控件的Event属性1.Location = new System.Drawing.Point(55, 48); this.secondControl自定义控件的Event属性1.Name = "secondControl自定义控件的Event属性1"; this.secondControl自定义控件的Event属性1.Size = new System.Drawing.Size(100, 20); this.secondControl自定义控件的Event属性1.TabIndex = 0; // // 之三窗体控件设计时Event属性Attribute // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.secondControl自定义控件的Event属性1); this.Name = "之三窗体控件设计时Event属性Attribute"; this.Text = "之三窗体控件设计时Event属性Attribute"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private WinFormControlLibrary.SecondControl自定义控件的Event属性 secondControl自定义控件的Event属性1; }}
添加完成后,我们就可以在设计时的属性栏中看见我们自定义的属性了。
关于设计时的Attribute就基本介绍到这里。
0 0
- 【WinForm窗体控件开发】之三续 窗体控件设计时的事件属性
- 【WinForm窗体控件开发】之三 窗体控件设计时属性Attribute
- 【Visual Studio风格开发系列 - WinForm设计时异常】关于VS.NET中窗体设计器初始化控件引发的设计时异常
- WinForm设计时异常】关于VS.NET中窗体设计器初始化控件引发的设计时异常
- 【WinForm窗体控件开发】之四 DesignerSerializationVisibilityAttribute 控件属性的串行化
- 【C#基础】之WinForm窗体常用控件的属性、方法及事件简介
- 【C#基础】之WinForm窗体常用控件的属性、方法及事件简介
- 【C#基础】之WinForm窗体常用控件的属性、方法及事件简介 .
- 【C#基础】之WinForm窗体常用控件的属性、方法及事件简介
- ASP.NET控件开发之属性设计时支持
- 窗体控件的事件
- 窗体控件的属性
- 关于VS.NET中窗体设计器初始化控件引发的设计时异常
- WinForm常用窗体属性及控件
- 【Winform窗体控件开发】之五 实现类型转换器TypeConverterAttribute
- c#,winform,UserContrl,用户控件开发,窗体
- 【WinForm窗体控件开发】之一 概述
- WinForm中一个窗体调用另一个窗体的控件和事件的方法(附带源码)
- JAVA_SE基础——42.final修饰符
- 第四周项目1 建立单链表
- POJ - 3087 Shuffle'm Up(15.10.10 搜索专题)模拟
- 统计ios工程代码总行数
- 在项目中使用volley
- 【WinForm窗体控件开发】之三续 窗体控件设计时的事件属性
- AllJoyn ABOUT ANNOUNCEMENT
- 关于”running yum-complete-transaction first” 的提示信息
- swift单例和oc单例
- OpenCV参考手册之Mat类详解1
- java入门第二天作业预习运算符
- 夏洛特烦恼 的感想
- [路由交换]OSPF网络类型、DR/BDR、邻居,邻接关系
- setAttribute and getAttribute的用法 以及阻止<a>的href的默认属性