簡體   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