c#自定義控件中事件的處理_.Net教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:ASP.NET利用MD.DLL轉(zhuǎn)EXCEL具體實(shí)現(xiàn)首先引入MD.dll 文件(附有下載地址)然后建立無CS文件的DownExcel.aspx 文件,接下來是調(diào)用方法,感興趣的朋友可以參考下哈
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.事件觸發(fā),這樣少了事件注冊,我們在其他窗體中引用控件時(shí)只需要注冊事件和編輯事件處理程序即可,可以對比上一篇博客 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(); } //新聞被點(diǎn)擊 事件觸發(fā)方法 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> /// 新聞標(biāo)題 /// </summary> private string _NewsTitle = ""; [Description("新聞標(biāo)題"), Category("Appearance")] public string NewsTitle { get { return _NewsTitle; } set { _NewsTitle = value; this.Invalidate(); } } private Color _MouseOnColor = new Color(); [Description("鼠標(biāo)劃上的樣色"), 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沒有數(shù)據(jù) 表頭不顯示的解決方法datagrid綁定list沒有數(shù)據(jù) 表頭不顯示的問題,那是因?yàn)?綁定了null,你給list new一下就好 表頭就會(huì)有啦
相關(guān).Net教程:
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實(shí)例(可帶附件)
- js實(shí)現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報(bào)表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲(chǔ)過程實(shí)現(xiàn)分頁示例代碼
.Net教程Rss訂閱編程教程搜索
.Net教程推薦
- DataTable數(shù)據(jù)導(dǎo)出成Excel文件的小例子
- ASP.NET畫圖全攻略(上)
- asp.net url重寫的好處與方法
- 動(dòng)態(tài)代理DynamicProxy 介紹
- c# 連接字符串?dāng)?shù)據(jù)庫服務(wù)器端口號(hào)
- 簡述c#中對字符串進(jìn)行分割的幾種方法
- asp.net初學(xué)者:petshop4.0設(shè)計(jì)說明
- 淺析微軟 ASP.NET 環(huán)境下的頁面驗(yàn)證控件
- ASP.NET站點(diǎn)RSS功能實(shí)現(xiàn)方法
- 解析6種ASP.NET跨頁面?zhèn)髦档姆椒?/a>
- 相關(guān)鏈接:
- 教程說明:
.Net教程-c#自定義控件中事件的處理。