玩无限消乐的设计示例(基础篇)DataGridView控件添加拖放事件方法和委托
2016-07-09 08:58
549 查看
给DataGridView控件添加拖放事件方法,预备交换动画元素。
为了方便把DataGridView控件改为全局声明,否则的话就要找到控件才能使用。查找代码: DataGridView 表格控件 = (DataGridView)this.Controls["玩无限消乐"];
添加拖放事件方法委托
private void Form1_Load(object sender, EventArgs e)
{
玩无限消乐.Name = "玩无限消乐";
玩无限消乐.AllowDrop = true;
玩无限消乐.AllowUserToAddRows = false;
玩无限消乐.AllowUserToOrderColumns = false;
玩无限消乐.AllowUserToResizeColumns = false;
玩无限消乐.AllowUserToResizeRows = false;
玩无限消乐.ReadOnly = true;
玩无限消乐.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
玩无限消乐.Location = new Point(0, 全屏截取.Height);
玩无限消乐.BackgroundColor = System.Drawing.Color.Linen;
玩无限消乐.ColumnHeadersVisible = false;
玩无限消乐.MultiSelect = false;
玩无限消乐.RowHeadersVisible = false;
玩无限消乐.BorderStyle = BorderStyle.None;
玩无限消乐.ScrollBars = ScrollBars.None;
玩无限消乐.Capture = true;
玩无限消乐.AutoSize = true;
玩无限消乐.CellBorderStyle = DataGridViewCellBorderStyle.None;
玩无限消乐.DefaultCellStyle.SelectionBackColor = Color.LightYellow;
//玩无限消乐.ColumnCount = 14;
//System.Threading.Thread.Sleep(2000);
int 列数 = 0, 数量 = 22;
while (列数++ < 数量)
{
DataGridViewImageColumn 新图列 = new DataGridViewImageColumn();
玩无限消乐.Columns.Add(新图列);
}
玩无限消乐.RowCount = 数量;
玩无限消乐.AutoResizeColumns();
//玩无限消乐.AutoResizeRows();
玩无限消乐.Parent = this;
玩无限消乐.DragDrop += new DragEventHandler(玩无限消乐_DragDrop);
玩无限消乐.DragEnter += new DragEventHandler(玩无限消乐_DragEnter);
玩无限消乐.CellMouseDown += new DataGridViewCellMouseEventHandler(玩无限消乐_CellMouseDown);
}
private void 玩无限消乐_DragDrop(object sender, DragEventArgs e) { Point 平面二维 = 玩无限消乐.PointToClient(new Point(e.X, e.Y)); 玩无限消除.Rows[玩无限消乐.HitTest(平面二维.X, 平面二维.Y).RowIndex].Cells[玩无限消乐.HitTest(平面二维.X, 平面二维.Y).ColumnIndex].Value = (System.Drawing.Bitmap)e.Data.GetData(typeof(System.Drawing.Bitmap));/*System.String*/ } private void 玩无限消乐_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void 玩无限消乐_CellEndEdit(object sender, DataGridViewCellEventArgs e) { 玩无限消乐.DoDragDrop(玩无限消乐.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, DragDropEffects.All); } private void 玩无限消乐_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { 玩无限消乐.DoDragDrop(玩无限消乐.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, DragDropEffects.All); }
为了方便把DataGridView控件改为全局声明,否则的话就要找到控件才能使用。查找代码: DataGridView 表格控件 = (DataGridView)this.Controls["玩无限消乐"];
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; using System.Threading; using System.IO; namespace Windows屏幕截图 { public partial class Form1 : Form { DataGridView 玩无限消乐 = new DataGridView(); } }
添加拖放事件方法委托
private void Form1_Load(object sender, EventArgs e)
{
玩无限消乐.Name = "玩无限消乐";
玩无限消乐.AllowDrop = true;
玩无限消乐.AllowUserToAddRows = false;
玩无限消乐.AllowUserToOrderColumns = false;
玩无限消乐.AllowUserToResizeColumns = false;
玩无限消乐.AllowUserToResizeRows = false;
玩无限消乐.ReadOnly = true;
玩无限消乐.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
玩无限消乐.Location = new Point(0, 全屏截取.Height);
玩无限消乐.BackgroundColor = System.Drawing.Color.Linen;
玩无限消乐.ColumnHeadersVisible = false;
玩无限消乐.MultiSelect = false;
玩无限消乐.RowHeadersVisible = false;
玩无限消乐.BorderStyle = BorderStyle.None;
玩无限消乐.ScrollBars = ScrollBars.None;
玩无限消乐.Capture = true;
玩无限消乐.AutoSize = true;
玩无限消乐.CellBorderStyle = DataGridViewCellBorderStyle.None;
玩无限消乐.DefaultCellStyle.SelectionBackColor = Color.LightYellow;
//玩无限消乐.ColumnCount = 14;
//System.Threading.Thread.Sleep(2000);
int 列数 = 0, 数量 = 22;
while (列数++ < 数量)
{
DataGridViewImageColumn 新图列 = new DataGridViewImageColumn();
玩无限消乐.Columns.Add(新图列);
}
玩无限消乐.RowCount = 数量;
玩无限消乐.AutoResizeColumns();
//玩无限消乐.AutoResizeRows();
玩无限消乐.Parent = this;
玩无限消乐.DragDrop += new DragEventHandler(玩无限消乐_DragDrop);
玩无限消乐.DragEnter += new DragEventHandler(玩无限消乐_DragEnter);
玩无限消乐.CellMouseDown += new DataGridViewCellMouseEventHandler(玩无限消乐_CellMouseDown);
}
相关文章推荐
- 关于TCP Zero Window Update感知的非常棒的优化
- 【树链剖分(区间线段树)】BZOJ4196-[NOI2015]软件包管理
- PHP面向对象技术(全面讲解)
- hdu 2124 Repair the Wall
- 虚函数表
- centos lnmp环境配置ssl证书支持https访问
- PHP的单例模式--三私一公
- 定时任务
- 常用正则表达式大全
- iOS中加载HTML数据,并点击图片或链接进行相应的操作
- Android 中 SQLite 性能优化
- Android4.4webview杂记
- GitHub上最火的Android开源项目
- <Android 基础(十七)> ViewPager
- <Android 基础(十七)> ViewPager介绍
- Codeforces 689D Friends and Subsequences(RMQ+二分)
- Android类加载
- matlab自学经验成果分享 创建一个复数
- 常用MFC的API函数
- C#新手入门代码 利用return 提前终止函数