DataGridViewImageColumn.ImageLayout 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
為此資料行取得或設定儲存格中的影像配置。
public:
property System::Windows::Forms::DataGridViewImageCellLayout ImageLayout { System::Windows::Forms::DataGridViewImageCellLayout get(); void set(System::Windows::Forms::DataGridViewImageCellLayout value); };
public System.Windows.Forms.DataGridViewImageCellLayout ImageLayout { get; set; }
member this.ImageLayout : System.Windows.Forms.DataGridViewImageCellLayout with get, set
Public Property ImageLayout As DataGridViewImageCellLayout
屬性值
指定儲存格配置的 DataGridViewImageCellLayout。 預設為 Normal。
例外狀況
CellTemplate 屬性的值是 null
。
範例
下列程式碼範例示範如何延展和縮放影像以容納儲存格。 此範例是如何在 Windows Forms DataGridView 控制項中使用影像資料行中較大範例的一部分。
void Stretch( Object^ sender, EventArgs^ e )
{
System::Collections::IEnumerator^ myEnum = dataGridView1->Columns->GetEnumerator();
while ( myEnum->MoveNext() )
{
DataGridViewImageColumn^ column = safe_cast<DataGridViewImageColumn^>(myEnum->Current);
column->ImageLayout = DataGridViewImageCellLayout::Stretch;
column->Description = L"Stretched";
}
}
void ZoomToImage( Object^ sender, EventArgs^ e )
{
System::Collections::IEnumerator^ myEnum1 = dataGridView1->Columns->GetEnumerator();
while ( myEnum1->MoveNext() )
{
DataGridViewImageColumn^ column = safe_cast<DataGridViewImageColumn^>(myEnum1->Current);
column->ImageLayout = DataGridViewImageCellLayout::Zoom;
column->Description = L"Zoomed";
}
}
void NormalImage( Object^ sender, EventArgs^ e )
{
System::Collections::IEnumerator^ myEnum2 = dataGridView1->Columns->GetEnumerator();
while ( myEnum2->MoveNext() )
{
DataGridViewImageColumn^ column = safe_cast<DataGridViewImageColumn^>(myEnum2->Current);
column->ImageLayout = DataGridViewImageCellLayout::Normal;
column->Description = L"Normal";
}
}
private void Stretch(object sender, EventArgs e)
{
foreach (DataGridViewImageColumn column in
dataGridView1.Columns)
{
column.ImageLayout = DataGridViewImageCellLayout.Stretch;
column.Description = "Stretched";
}
}
private void ZoomToImage(object sender, EventArgs e)
{
foreach (DataGridViewImageColumn column in
dataGridView1.Columns)
{
column.ImageLayout = DataGridViewImageCellLayout.Zoom;
column.Description = "Zoomed";
}
}
private void NormalImage(object sender, EventArgs e)
{
foreach (DataGridViewImageColumn column in
dataGridView1.Columns)
{
column.ImageLayout = DataGridViewImageCellLayout.Normal;
column.Description = "Normal";
}
}
Private Sub Stretch(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button3.Click
For Each column As DataGridViewImageColumn _
In dataGridView1.Columns
column.ImageLayout = DataGridViewImageCellLayout.Stretch
column.Description = "Stretched image layout"
Next
End Sub
Private Sub ZoomToImage(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button4.Click
For Each column As DataGridViewImageColumn _
In dataGridView1.Columns
column.ImageLayout = DataGridViewImageCellLayout.Zoom
column.Description = "Zoomed image layout"
Next
End Sub
Private Sub NormalImage(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button5.Click
For Each column As DataGridViewImageColumn _
In dataGridView1.Columns
column.ImageLayout = DataGridViewImageCellLayout.Normal
column.Description = "Normal image layout"
Next
End Sub
備註
取得或設定這個屬性會取得或設定 ImageLayout 屬性所 CellTemplate 傳回之物件的 屬性。 設定此屬性也會設定 ImageLayout 資料行中每個儲存格的屬性,並重新整理資料行顯示。 若要覆寫個別儲存格的指定值,請在設定資料行值之後設定儲存格值。