我试图在datagridview中设置列中图标的大小:
// .. previous code to fill a dataset with rows of data ...
// Assign dataset into the DataGridView
this.dataGridView1.DataSource = thisDataSet.Tables[0];
// Create icon resource
Icon icon1 = new Icon(SystemIcons.Exclamation, 8, 8);
// Create a column to hold an icon
DataGridViewImageColumn img = new DataGridViewImageColumn(true);
// Set icon for all rows in the column
img.Icon = icon1;
// Add column to right side of the DataGridView
this.dataGridView1.Columns.Add(img);
// Move it to the beginning (left side)
this.dataGridView1.Columns[this.dataGridView1.Columns.Count - 1].DisplayIndex = 0;我的DataGridView显示得很好,左边有一个列,每一行都有一个图标。所有图标的大小都与预期相同,但它们看上去太大,无法达到8x8像素,即使我指定了自己的大小。如何控制图标大小?
发布于 2013-09-20 15:45:48
由于某些原因,在Size构造函数中传递的Icon被忽略了,我认为您可以尝试使用Image属性,如下所示:
img.Image = new Bitmap(SystemIcons.Exclamation.ToBitmap(), 8, 8);发布于 2018-02-02 00:23:33
您需要将ImageLayout属性设置为正常。
DataGridViewImageColumn.ImageLayout = DataGridViewImageCellLayout.Normalhttps://stackoverflow.com/questions/18920433
复制相似问题