DataGridViewImageColumn.Image 屬性

定義

當未設定儲存格的 Value 屬性且儲存格的 ValueIsIcon 屬性設定為 false 時,取得或設定此資料行的儲存格內所顯示的影像。Gets or sets the image displayed in the cells of this column when the cell's Value property is not set and the cell's ValueIsIcon property is set to false.

public:
 property System::Drawing::Image ^ Image { System::Drawing::Image ^ get(); void set(System::Drawing::Image ^ value); };
public System.Drawing.Image Image { get; set; }
member this.Image : System.Drawing.Image with get, set
Public Property Image As Image

屬性值

要顯示的 ImageThe Image to display. 預設為 nullThe default is null.

範例

下列程式碼範例示範如何設定預設影像。The following code example demonstrates how to set the default image. 這個範例是中所提供之較大範例的一部分。使用 Windows Forms DataGridView 控制項中的影像資料行。This example is part of a larger example available in How to: Work with Image Columns in the Windows Forms DataGridView Control.

void CreateColumns()
{
   DataGridViewImageColumn^ imageColumn;
   int columnCount = 0;
   do
   {
      Bitmap^ unMarked = blank;
      imageColumn = gcnew DataGridViewImageColumn;
      
      //Add twice the padding for the left and 
      //right sides of the cell.
      imageColumn->Width = x->Width + 2 * bitmapPadding + 1;
      imageColumn->Image = unMarked;
      dataGridView1->Columns->Add( imageColumn );
      columnCount = columnCount + 1;
   }
   while ( columnCount < 3 );
}


private void CreateColumns()
{
    DataGridViewImageColumn imageColumn;
    int columnCount = 0;
    do
    {
        Bitmap unMarked = blank;
        imageColumn = new DataGridViewImageColumn();

        //Add twice the padding for the left and 
        //right sides of the cell.
        imageColumn.Width = x.Width + 2 * bitmapPadding + 1;

        imageColumn.Image = unMarked;
        dataGridView1.Columns.Add(imageColumn);
        columnCount = columnCount + 1;
    }
    while (columnCount < 3);
}
Private Sub CreateColumns()

    Dim imageColumn As DataGridViewImageColumn
    Dim columnCount As Integer = 0
    Do
        Dim unMarked As Bitmap = blank
        imageColumn = New DataGridViewImageColumn()

        ' Add twice the padding for the left and 
        ' right sides of the cell.
        imageColumn.Width = x.Width + 2 * bitmapPadding + 1

        imageColumn.Image = unMarked
        imageColumn.ImageLayout = DataGridViewImageCellLayout.NotSet
        imageColumn.Description = "default image layout"
        dataGridView1.Columns.Add(imageColumn)
        columnCount = columnCount + 1
    Loop While columnCount < 3
End Sub

備註

當資料行不是資料系結時, ValueIsIcon false屬性會指定在沒有值的儲存格中顯示的影像,而且儲存格的屬性Image會設定為。The Image property specifies an image that is displayed in cells with no values when the column is not data-bound and the cell's ValueIsIcon property is set to false. 對於資料格沒有關聯影像的資料系結資料行, 會顯示標準的錯誤圖形。For a data-bound column whose cells do not have an associated image, a standard error graphic is displayed.

如果您想Icon要顯示Image, 而不是, 請改Icon為設定屬性, 並ValuesAreIcons將屬性true設定為。If you want to display an Icon instead of an Image, set the Icon property instead and set the ValuesAreIcons property to true. 這可確保的 Alpha Icon色板正確繪製。This ensures that the alpha channel of the Icon is painted correctly. 您也可以設定個別ValueIsIcon資料格的屬性, 以指出資料格是否會Image在沒有Icon儲存格值時顯示或屬性值。You can also set the ValueIsIcon property of individual cells to indicate whether the cell displays the Image or the Icon property value when there is no cell value.

適用於

另請參閱