winform datagridview 中其中有一列为DataGridViewButtonColumn
想要在 DataGridViewButtonColumn 上 做成一个图片按钮
应该如何添加上图片按钮呢?
设置:e.Handled = true; private void grid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex < 0) return; if (e.ColumnIndex == 0) { e.Paint(e.CellBounds, DataGridViewPaintParts.All); var w = Properties.Resources.SomeImage.Width; var h = Properties.Resources.SomeImage.Height; var x = e.CellBounds.Left + (e.CellBounds.Width - w) / 2; var y = e.CellBounds.Top + (e.CellBounds.Height - h) / 2; e.Graphics.DrawImage(someImage, new Rectangle(x, y, w, h)); e.Handled = true; } } dataGridView1.Columns.Add(new DataGridViewImageColumn(){ Image = someImage, Name = "someName", HeaderText = "Some Text" }); void grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.RowIndex < 0) return; if (e.ColumnIndex == 1) e.Value = someImage; } void grid_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) return; if (e.ColumnIndex == 1) MessageBox.Show("Clicked!"); }