c#自定义控件中事件的处理_.Net教程
教程Tag:暂无Tag,欢迎添加,赚取U币!
推荐:ASP.NET利用MD.DLL转EXCEL具体实现首先引入MD.dll 文件(附有下载地址)然后建立无CS文件的DownExcel.aspx 文件,接下来是调用方法,感兴趣的朋友可以参考下哈
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ClientControl { //1.定义委托 public delegate void NewsClickEventHandle(object sender,NewsEventArg args); public partial class NewsStage : Control { //2.定义事件 public event NewsClickEventHandle NewsClicked; private Graphics g; private bool isMouseOn = false; public NewsStage() { InitializeComponent(); //3.事件触发,这样少了事件注册,我们在其他窗体中引用控件时只需要注册事件和编辑事件处理程序即可,可以对比上一篇博客 this.Click += new EventHandler(NewsStage_Click); this.MouseMove += new MouseEventHandler(NewsStage_MouseMove); this.MouseLeave += new EventHandler(NewsStage_MouseLeave); } void NewsStage_MouseLeave(object sender, EventArgs e) { isMouseOn = false; this.Invalidate(); } void NewsStage_MouseMove(object sender, MouseEventArgs e) { isMouseOn = true; this.Invalidate(); } //新闻被点击 事件触发方法 void NewsStage_Click(object sender, EventArgs e) { if (_NewsID>=0&&_NewsTitle!="") { NewsEventArg myArgs = new NewsEventArg(_NewsID,_NewsTitle); NewsClicked(this, myArgs); } } private int _NewsID = 0; [Description("新闻ID"), Category("Appearance")] public int NewsID { get { return _NewsID; } set { _NewsID = value; this.Invalidate(); } } /// <summary> /// 新闻标题 /// </summary> private string _NewsTitle = ""; [Description("新闻标题"), Category("Appearance")] public string NewsTitle { get { return _NewsTitle; } set { _NewsTitle = value; this.Invalidate(); } } private Color _MouseOnColor = new Color(); [Description("鼠标划上的样色"), Category("Appearance")] public Color MouseOnColor { get { return _MouseOnColor; } set { _MouseOnColor = value; } } protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); g = this.CreateGraphics(); if (isMouseOn) { g.DrawString(_NewsTitle, this.Font, new SolidBrush(this._MouseOnColor), new PointF(0, 0)); } else { g.DrawString(_NewsTitle, this.Font, new SolidBrush(this.ForeColor), new PointF(0, 0)); } } protected void Dispose() { g.Dispose(); } } public partial class NewsEventArg : EventArgs { public int NewsID = 0; public string NewsTitle = ""; public NewsEventArg(int newsID,string newsTitle){ NewsID = newsID; NewsTitle = newsTitle; } } }分享:datagrid绑定list没有数据 表头不显示的解决方法datagrid绑定list没有数据 表头不显示的问题,那是因为 绑定了null,你给list new一下就好 表头就会有啦
相关.Net教程:
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP发送Email实例(可带附件)
- js实现广告漂浮效果的小例子
- asp.net Repeater 数据绑定的具体实现
- Asp.Net 无刷新文件上传并显示进度条的实现方法及思路
- Asp.net获取客户端IP常见代码存在的伪造IP问题探讨
- VS2010 水晶报表的使用方法
- ASP.NET中操作SQL数据库(连接字符串的配置及获取)
- asp.net页面传值测试实例代码
- DataGridView - DataGridViewCheckBoxCell的使用介绍
- asp.net中javascript的引用(直接引入和间接引入)
- 三层+存储过程实现分页示例代码
- 相关链接:
- 教程说明:
.Net教程-c#自定义控件中事件的处理。