怎样点击一个cell然后在这个cell上添加一个按钮

怎样点击一个cell然后在这个cell上添加一个按钮,第1张

说说自己的思路,首先你要自定义cell,cell上贴了一个删除的button,然后在你点击某个button以后,button设置不隐藏,你关键需要动画,那么自定义一个button继承自uibutton,给这个自定义button添加一个动画方法,动画如果我想,没有这样动画的,你可以拿一张和cell背景颜色一样的图片,然后慢慢移动,这样就造成了button慢慢显示的假象,仅供参考

public Form1()

{

InitializeComponent()

this.Load += new EventHandler(Form1_Load)

}

List<string>strSourec = new List<string>{ "1", "2" }

void Form1_Load(object sender, EventArgs e)

{

foreach (string item in strSourec)

{

DataGridViewButtonColumn Column1 = new DataGridViewButtonColumn()

Column1.HeaderText = item

this.dataGridView1.Columns.Add(Column1)

}

DataGridViewRow dr = new DataGridViewRow()

for (int i = 0i <strSourec.Counti++)

{

DataGridViewButtonCell dgvbc = new DataGridViewButtonCell()

dgvbc.Value = strSourec[i]

dr.Cells.Add(dgvbc)

}

dataGridView1.Rows.Add(dr)

this.dataGridView1.CellMouseDown += new DataGridViewCellMouseEventHandler(dataGridView1_CellMouseDown)

}

void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)

{

if (dataGridView1[e.ColumnIndex, e.RowIndex].Value == null) return

MessageBox.Show(dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString())

}

参考:

http://zhidao.baidu.com/link?url=JImY3prv3dVBJlYSnTOIenUJnx6xyRRVFZYpnmg_flu755xA7RgADZtRswoKr1QMcCjClxWjmbHtRgsyFnZYya

不明白的再私信我


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11819534.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存