成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

當前位置:首頁>>開發編程>>VS.NET>>新聞內容
捕捉DataGrid的雙擊事件(C#版本)
作者:佚名 發布時間:2004-9-28 23:08:01 文章來源:西部E網
namespace DataGridDoubleClick { using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.DataGrid dataGrid1; private DataSet myDataSet; DateTime gridMouseDownTime; private System.Windows.Forms.Label label1; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); gridMouseDownTime = DateTime.Now; SetUp(); } private void SetUp() { // 用2個Table和1和Relation創建DataSet MakeDataSet(); // 數據綁定 dataGrid1.SetDataBinding(myDataSet, "Customers"); //添加樣式 AddCustomDataTableStyle(); } private void MakeDataSet() { // 創建DataSet. myDataSet = new DataSet("myDataSet"); // 創建2個DataTables. DataTable tCust = new DataTable("Customers"); // 創建兩個列,并添加到第一個表 DataColumn cCustID = new DataColumn("custID"); DataColumn cCustName = new DataColumn("custName"); DataColumn cCurrent = new DataColumn("custCity"); tCust.Columns.Add(cCustID); tCust.Columns.Add(cCustName); tCust.Columns.Add(cCurrent); // 把tables添加到DataSet. myDataSet.Tables.Add(tCust); /* 計算tables.對每個客戶,創建DataRow變量 */ DataRow newRow1; // 添加記錄到 Customers Table. for(int i = 1; i < 4; i++) { newRow1 = tCust.NewRow(); newRow1["custID"] = (100*i).ToString(); tCust.Rows.Add(newRow1); } tCust.Rows[0]["custName"] = "【孟憲會之精彩世界】"; tCust.Rows[1]["custName"] = "net_lover"; tCust.Rows[2]["custName"] = "http://xml.sz.luohuedu.net/"; tCust.Rows[0]["custCity"] = "北京"; tCust.Rows[1]["custCity"] = "上海"; tCust.Rows[2]["custCity"] = "河南"; } private void AddCustomDataTableStyle() { DataGridTableStyle ts1 = new DataGridTableStyle(); ts1.MappingName = "Customers"; // 設置屬性 ts1.AlternatingBackColor = Color.LightGray; // 添加Textbox列樣式,以便我們捕捉鼠標事件 DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn(); TextCol.MappingName = "custID"; TextCol.HeaderText = "序號"; TextCol.Width = 100; //添加事件處理器 TextCol.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler); TextCol.TextBox.DoubleClick += new EventHandler(TextBoxDoubleClickHandler); ts1.GridColumnStyles.Add(TextCol); TextCol = new DataGridTextBoxColumn(); TextCol.MappingName = "custName"; TextCol.HeaderText = "姓名"; TextCol.Width = 100; //添加事件處理器 TextCol.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler); TextCol.TextBox.DoubleClick += new EventHandler(TextBoxDoubleClickHandler); ts1.GridColumnStyles.Add(TextCol); TextCol = new DataGridTextBoxColumn(); TextCol.MappingName = "custCity"; TextCol.HeaderText = "地址"; TextCol.Width = 100; //添加事件處理器 TextCol.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler); TextCol.TextBox.DoubleClick += new EventHandler(TextBoxDoubleClickHandler); ts1.GridColumnStyles.Add(TextCol); dataGrid1.TableStyles.Add(ts1); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.dataGrid1 = new System.Windows.Forms.DataGrid(); this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.SuspendLayout(); // // dataGrid1 // this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Info; this.dataGrid1.CaptionForeColor = System.Drawing.SystemColors.WindowText; this.dataGrid1.CaptionVisible = false; this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point(11, 9); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(368, 144); this.dataGrid1.TabIndex = 0; this.dataGrid1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dataGrid1_MouseDown); // // label1 // this.label1.Location = new System.Drawing.Point(4, 166); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(383, 23); this.label1.TabIndex = 1; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.label1.Click += new System.EventHandler(this.Form1_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(387, 201); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.label1, this.dataGrid1}); this.Name = "Form1"; this.Text = "鼠標雙擊事件的例子"; ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } private void TextBoxDoubleClickHandler(object sender, EventArgs e) { MessageBox.Show("雙擊事件發生。鼠標雙擊到的值:"+((TextBox)sender).Text.ToString()); } private void TextBoxMouseDownHandler(object sender, MouseEventArgs e) { if(DateTime.Now < gridMouseDownTime.AddMilliseconds(SystemInformation.DoubleClickTime)) { MessageBox.Show("雙擊事件發生。鼠標雙擊到的值:"+((TextBox)sender).Text.ToString()); } label1.Text = "TextBox 鼠標按下了。 "; } private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { gridMouseDownTime = DateTime.Now; label1.Text = "DataGrid1 鼠標按下了。 "; } private void Form1_Click(object sender, System.EventArgs e) { label1.Text=""; } private void label1_Click(object sender, System.EventArgs e) { label1.Text=""; } } }
最新更新
·C#中使用Split分隔字符串的技
·VS2008開發中Windows Mobile
·PC機和移動設備上絕對路徑的
·C#程序加殼的方法(使用Sixx
·當前上下文中不存在名稱Conf
·請插入磁盤:Visual Studio 2
·用VS.NET讀取Flash格式文件信
·在ASP.NET中使用AJAX的簡單方
·VS.NET 2005中常用的一些代碼
·安裝VS.NET 2005 SP1補丁全攻
相關信息
畫心
愚愛
偏愛
火苗
白狐
畫沙
犯錯
歌曲
傳奇
稻香
小酒窩
獅子座
小情歌
全是愛
棉花糖
海豚音
我相信
甩蔥歌
這叫愛
shero
走天涯
琉璃月
Nobody
我愛他
套馬桿
愛是你我
最后一次
少女時代
灰色頭像
斷橋殘雪
美了美了
狼的誘惑
我很快樂
星月神話
心痛2009
愛丫愛丫
半城煙沙
旗開得勝
郎的誘惑
愛情買賣
2010等你來
我叫小沈陽
i miss you
姑娘我愛你
我們都一樣
其實很寂寞
我愛雨夜花
變心的玫瑰
犀利哥之歌
你是我的眼
你是我的OK繃
貝多芬的悲傷
哥只是個傳說
丟了幸福的豬
找個人來愛我
要嫁就嫁灰太狼
如果這就是愛情
我們沒有在一起
寂寞在唱什么歌
斯琴高麗的傷心
別在我離開之前離開
不是因為寂寞才想你
愛上你等于愛上了錯
在心里從此永遠有個你
一個人的寂寞兩個人的錯
主站蜘蛛池模板: 揭西县| 商河县| 宽城| 民权县| 葫芦岛市| 威海市| 磐石市| 自治县| 盐城市| 自治县| 克拉玛依市| 昌江| 扎兰屯市| 宿州市| 怀安县| 始兴县| 大城县| 博爱县| 德惠市| 开平市| 察隅县| 敖汉旗| 大宁县| 金湖县| 左权县| 隆子县| 梁平县| 平潭县| 舒城县| 阿城市| 河津市| 嘉黎县| 稷山县| 重庆市| 武乡县| 凌云县| 荃湾区| 吴旗县| 常山县| 鄱阳县| 渝中区|