繁体   English   中英

在DataGridViewImageColumn中设置图标的大小

[英]Set size of icon in DataGridViewImageColumn

我正在尝试在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像素。 如何控制图标大小?

由于某种原因, 忽略Icon构造函数中传递的Size ,我认为您可以尝试使用Image属性来代替:

img.Image = new Bitmap(SystemIcons.Exclamation.ToBitmap(), 8, 8);

您需要将ImageLayout属性设置为Normal。

DataGridViewImageColumn.ImageLayout = DataGridViewImageCellLayout.Normal

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM