DataGridViewImageCell 类

定义

显示 DataGridView 控件中的图形。

public ref class DataGridViewImageCell : System::Windows::Forms::DataGridViewCell
public class DataGridViewImageCell : System.Windows.Forms.DataGridViewCell
type DataGridViewImageCell = class
    inherit DataGridViewCell
Public Class DataGridViewImageCell
Inherits DataGridViewCell
继承

示例

下面的代码示例演示如何使用 DataGridViewCell更改图像单元格中的图像。 此代码示例是主题How to: Work with Image Columns in the Windows 窗体 DataGridView 控件提供的更大示例的一部分。

void dataGridView1_CellClick( Object^ sender, DataGridViewCellEventArgs^ e )
{
   if ( turn->Equals( gameOverString ) )
   {
      return;
   }

   DataGridViewImageCell^ cell = dynamic_cast<DataGridViewImageCell^>(dataGridView1->Rows[ e->RowIndex ]->Cells[ e->ColumnIndex ]);
   if ( cell->Value == blank )
   {
      if ( IsOsTurn() )
      {
         cell->Value = o;
      }
      else
      {
         cell->Value = x;
      }

      ToggleTurn();
   }

   if ( IsAWin( cell ) )
   {
      turn->Text = gameOverString;
   }
}
private void dataGridView1_CellClick(object sender,
    DataGridViewCellEventArgs e)
{

    if (turn.Text.Equals(gameOverString)) { return; }

    DataGridViewImageCell cell = (DataGridViewImageCell)
        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];

    if (cell.Value == blank)
    {
        if (IsOsTurn())
        {
            cell.Value = o;
        }
        else
        {
            cell.Value = x;
        }
        ToggleTurn();
    }
    if (IsAWin())
    {
        turn.Text = gameOverString;
    }
}
Private Sub dataGridView1_CellClick(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dataGridView1.CellClick

    If turn.Text.Equals(gameOverString) Then Return

    Dim cell As DataGridViewImageCell = _
        CType(dataGridView1.Rows(e.RowIndex). _
            Cells(e.ColumnIndex), DataGridViewImageCell)
    If (cell.Value Is blank) Then
        If IsOsTurn() Then
            cell.Value = o
        Else
            cell.Value = x
        End If
        ToggleTurn()
        ToolTip(e)
    End If
    If IsAWin() Then
        turn.Text = gameOverString
    End If
End Sub

注解

DataGridViewImageCell是用于显示 ImageIcon的专用类型DataGridViewCell,具体取决于 属性的值ValueIsIcon。 通常, ReadOnlyDataGridViewImageCell 属性设置为 true ,以指示用户无法编辑单元格内容。

DataGridViewImageColumn是专用于保存此类型的单元格的列类型。 默认情况下, DataGridViewImageColumn.CellTemplate 初始化为新的 DataGridViewImageCell。 若要在现有 DataGridViewImageCell之后对列中的单元格进行图案化,请将列的 CellTemplate 属性设置为要用作模式的单元格。

列的单元格相关属性是模板单元格中类似名称的属性的包装器。 更改模板单元格的属性值将仅影响基于更改后添加的模板的单元格。 但是,更改列的单元格相关属性值将更新模板单元格和列中的所有其他单元格,并在必要时刷新列显示。

继承者说明

DataGridViewImageCell 派生类并将新属性添加到派生类时,请务必重写 Clone() 方法,以在克隆操作期间复制新属性。 还应调用基类的 Clone() 方法,以便将基类的属性复制到新单元格。

构造函数

DataGridViewImageCell()

初始化 DataGridViewImageCell 类的新实例,配置该实例以便用于单元格值而不是 Icon 对象。

DataGridViewImageCell(Boolean)

初始化 DataGridViewImageCell 类的新实例,可以选择配置它以用于 Icon 单元格值。

属性

AccessibilityObject

获取分配给 DataGridViewCell.DataGridViewCellAccessibleObjectDataGridViewCell

(继承自 DataGridViewCell)
ColumnIndex

获取此单元格的列索引。

(继承自 DataGridViewCell)
ContentBounds

获取环绕单元格内容区域的边框。

(继承自 DataGridViewCell)
ContextMenuStrip

获取或设置与单元格关联的快捷菜单。

(继承自 DataGridViewCell)
DataGridView

获取与此元素关联的 DataGridView 控件。

(继承自 DataGridViewElement)
DefaultNewRowValue

获取创建新行时使用的默认值。

Description

获取或设置与图像关联的文本。

Displayed

获取一个值,该值指示当前该单元格是否显示在屏幕上。

(继承自 DataGridViewCell)
EditedFormattedValue

获取该单元格的当前格式化值,而不考虑该单元格是否处于编辑模式,也不论是否尚未提交此值。

(继承自 DataGridViewCell)
EditType

获取单元格的寄宿编辑控件的类型。

ErrorIconBounds

获取单元格的错误图标的界限。

(继承自 DataGridViewCell)
ErrorText

获取或设置描述与该单元格关联的错误条件的文本。

(继承自 DataGridViewCell)
FormattedValue

获取为显示进行格式化的单元格的值。

(继承自 DataGridViewCell)
FormattedValueType

获取与单元格关联的格式化值的类型。

Frozen

获取指示单元格是否已被冻结的值。

(继承自 DataGridViewCell)
HasStyle

获取指示是否已设置 Style 属性的值。

(继承自 DataGridViewCell)
ImageLayout

获取或设置单元格的图形布局。

InheritedState

获取该单元格从它的行和列的状态继承后的当前状态。

(继承自 DataGridViewCell)
InheritedStyle

获取当前应用于单元格的样式。

(继承自 DataGridViewCell)
IsInEditMode

获取一个值,该值指示此单元格当前是否处于编辑状态。

(继承自 DataGridViewCell)
OwningColumn

获取包含此单元格的列。

(继承自 DataGridViewCell)
OwningRow

获取包含此单元格的行。

(继承自 DataGridViewCell)
PreferredSize

获取适合该单元格的矩形区域的大小(以像素为单位)。

(继承自 DataGridViewCell)
ReadOnly

获取或设置一个值,该值表示是否可以编辑该单元格的数据。

(继承自 DataGridViewCell)
Resizable

获取一个值,该值指示是否可以调整单元格的大小。

(继承自 DataGridViewCell)
RowIndex

获取单元格父行的索引。

(继承自 DataGridViewCell)
Selected

获取或设置一个值,该值指示是否已选定该单元格。

(继承自 DataGridViewCell)
Size

获取单元格的大小。

(继承自 DataGridViewCell)
State

获取元素的用户界面 (UI) 状态。

(继承自 DataGridViewElement)
Style

获取或设置单元格的样式。

(继承自 DataGridViewCell)
Tag

获取或设置包含有关单元格补充数据的对象。

(继承自 DataGridViewCell)
ToolTipText

获取或设置与此单元格关联的 ToolTip 文本。

(继承自 DataGridViewCell)
Value

获取或设置与此单元格关联的值。

(继承自 DataGridViewCell)
ValueIsIcon

获取或设置一个值,它指示该单元格是否显示 Icon 值。

ValueType

获取或设置单元格中值的数据类型。

Visible

获取一个值,该值指示单元格是否位于已隐藏的行或列中。

(继承自 DataGridViewCell)

方法

AdjustCellBorderStyle(DataGridViewAdvancedBorderStyle, DataGridViewAdvancedBorderStyle, Boolean, Boolean, Boolean, Boolean)

根据指定条件修改输入单元格的边框样式。

(继承自 DataGridViewCell)
BorderWidths(DataGridViewAdvancedBorderStyle)

返回一个 Rectangle,它表示所有单元格的边距宽度。

(继承自 DataGridViewCell)
ClickUnsharesRow(DataGridViewCellEventArgs)

指示在单击单元格时,是否对单元格所在的行取消共享。

(继承自 DataGridViewCell)
Clone()

创建此单元格的精确副本。

ContentClickUnsharesRow(DataGridViewCellEventArgs)

指示在单击单元格的内容时,是否对该单元格所在的行取消共享。

(继承自 DataGridViewCell)
ContentDoubleClickUnsharesRow(DataGridViewCellEventArgs)

指示在双击单元格的内容时,是否对该单元格所在的行取消共享。

(继承自 DataGridViewCell)
CreateAccessibilityInstance()

DataGridViewImageCell 创建一个新的可访问对象。

DetachEditingControl()

DataGridView 中删除单元格的编辑控件。

(继承自 DataGridViewCell)
Dispose()

释放由 DataGridViewCell 使用的所有资源。

(继承自 DataGridViewCell)
Dispose(Boolean)

释放由 DataGridViewCell 占用的非托管资源,还可以另外再释放托管资源。

(继承自 DataGridViewCell)
DoubleClickUnsharesRow(DataGridViewCellEventArgs)

指示在双击单元格时,是否对该单元格所在的行取消共享。

(继承自 DataGridViewCell)
EnterUnsharesRow(Int32, Boolean)

指示在焦点移到某单元格时,是否对相应父行取消共享。

(继承自 DataGridViewCell)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetClipboardContent(Int32, Boolean, Boolean, Boolean, Boolean, String)

检索要复制到 Clipboard 的单元格的已设置格式的值。

(继承自 DataGridViewCell)
GetContentBounds(Graphics, DataGridViewCellStyle, Int32)

返回围绕单元格内容区域的边框,该区域是使用指定的 Graphics 和单元格样式计算的。

GetContentBounds(Int32)

使用默认的 Graphics 和单元格当前应用的单元格样式,返回围绕单元格内容区域的边框。

(继承自 DataGridViewCell)
GetEditedFormattedValue(Int32, DataGridViewDataErrorContexts)

返回该单元格的当前格式化值,而不考虑该单元格是否处于编辑模式,也无论是否尚未提交此值。

(继承自 DataGridViewCell)
GetErrorIconBounds(Graphics, DataGridViewCellStyle, Int32)

如果显示了单元格的错误图标,则返回环绕该图标的边框。

GetErrorText(Int32)

返回表示单元格错误的字符串。

(继承自 DataGridViewCell)
GetFormattedValue(Object, Int32, DataGridViewCellStyle, TypeConverter, TypeConverter, DataGridViewDataErrorContexts)

将图形当作要在单元格中显示的内容返回。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetInheritedContextMenuStrip(Int32)

获取当前单元格的继承快捷菜单。

(继承自 DataGridViewCell)
GetInheritedState(Int32)

返回一个值,该值指示此单元格从它的行和列的状态继承后的当前状态。

(继承自 DataGridViewCell)
GetInheritedStyle(DataGridViewCellStyle, Int32, Boolean)

获取应用于单元格的样式。

(继承自 DataGridViewCell)
GetPreferredSize(Graphics, DataGridViewCellStyle, Int32, Size)

计算单元格的首选大小(以像素为单位)。

GetSize(Int32)

获取单元格的大小。

(继承自 DataGridViewCell)
GetType()

获取当前实例的 Type

(继承自 Object)
GetValue(Int32)

获取单元格的值。

InitializeEditingControl(Int32, Object, DataGridViewCellStyle)

初始化用于编辑单元格的控件。

(继承自 DataGridViewCell)
KeyDownUnsharesRow(KeyEventArgs, Int32)

指示在焦点位于单元格上,同时用户按任意键时,是否对父行取消共享。

(继承自 DataGridViewCell)
KeyEntersEditMode(KeyEventArgs)

确定是否应基于给定键启动编辑模式。

(继承自 DataGridViewCell)
KeyPressUnsharesRow(KeyPressEventArgs, Int32)

指示在焦点位于该行的单元格上并同时按任意键时,是否取消行的共享。

(继承自 DataGridViewCell)
KeyUpUnsharesRow(KeyEventArgs, Int32)

指示当焦点位于单元格上,同时用户释放某个键时,是否对父行取消共享。

(继承自 DataGridViewCell)
LeaveUnsharesRow(Int32, Boolean)

指示在焦点离开某行的单元格时,是否对该行取消共享。

(继承自 DataGridViewCell)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MouseClickUnsharesRow(DataGridViewCellMouseEventArgs)

指示在鼠标指针位于某行的单元格上,同时用户单击鼠标按钮时,是否应对该行取消共享。

(继承自 DataGridViewCell)
MouseDoubleClickUnsharesRow(DataGridViewCellMouseEventArgs)

指示当用户双击行中的单元格时,是否将对该行取消共享。

(继承自 DataGridViewCell)
MouseDownUnsharesRow(DataGridViewCellMouseEventArgs)

指示在指针位于行中某个单元格上,同时用户按住鼠标按钮时,是否对该行取消共享。

(继承自 DataGridViewCell)
MouseEnterUnsharesRow(Int32)

指示当鼠标指针移过行中某个单元格上时,该行是否取消共享状态。

(继承自 DataGridViewCell)
MouseLeaveUnsharesRow(Int32)

指示当鼠标指针离开某行时,该行是否取消共享状态。

(继承自 DataGridViewCell)
MouseMoveUnsharesRow(DataGridViewCellMouseEventArgs)

指示当鼠标指针移过行中某个单元格上时,该行是否取消共享状态。

(继承自 DataGridViewCell)
MouseUpUnsharesRow(DataGridViewCellMouseEventArgs)

指示在鼠标指针位于行中某个单元格上,同时用户释放鼠标按钮时,是否对该行取消共享。

(继承自 DataGridViewCell)
OnClick(DataGridViewCellEventArgs)

在单击单元格时进行调用。

(继承自 DataGridViewCell)
OnContentClick(DataGridViewCellEventArgs)

在单击单元格的内容时进行调用。

(继承自 DataGridViewCell)
OnContentDoubleClick(DataGridViewCellEventArgs)

在双击单元格的内容时进行调用。

(继承自 DataGridViewCell)
OnDataGridViewChanged()

在单元格的 DataGridView 属性更改时调用。

(继承自 DataGridViewCell)
OnDoubleClick(DataGridViewCellEventArgs)

在双击单元格时进行调用。

(继承自 DataGridViewCell)
OnEnter(Int32, Boolean)

在焦点移动到单元格时进行调用。

(继承自 DataGridViewCell)
OnKeyDown(KeyEventArgs, Int32)

在焦点位于单元格上并同时按下字符键时进行调用。

(继承自 DataGridViewCell)
OnKeyPress(KeyPressEventArgs, Int32)

在焦点位于单元格上并同时按任意键时进行调用。

(继承自 DataGridViewCell)
OnKeyUp(KeyEventArgs, Int32)

在焦点位于单元格上并同时释放字符键时进行调用。

(继承自 DataGridViewCell)
OnLeave(Int32, Boolean)

当焦点从单元格上移开时调用。

(继承自 DataGridViewCell)
OnMouseClick(DataGridViewCellMouseEventArgs)

在指针位于单元格上且用户同时单击鼠标按钮时进行调用。

(继承自 DataGridViewCell)
OnMouseDoubleClick(DataGridViewCellMouseEventArgs)

在指针位于单元格上,同时用户双击鼠标按钮时进行调用。

(继承自 DataGridViewCell)
OnMouseDown(DataGridViewCellMouseEventArgs)

在指针位于单元格上,同时用户按住鼠标按钮时进行调用。

(继承自 DataGridViewCell)
OnMouseEnter(Int32)

当鼠标指针移到单元格上时调用。

(继承自 DataGridViewCell)
OnMouseLeave(Int32)

在鼠标指针离开单元格时调用。

(继承自 DataGridViewCell)
OnMouseMove(DataGridViewCellMouseEventArgs)

当鼠标指针在单元格内移动时调用。

(继承自 DataGridViewCell)
OnMouseUp(DataGridViewCellMouseEventArgs)

在指针位于单元格上,同时用户释放鼠标按钮时进行调用。

(继承自 DataGridViewCell)
Paint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts)

绘制当前的 DataGridViewImageCell

PaintBorder(Graphics, Rectangle, Rectangle, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle)

绘制当前 DataGridViewCell 的边框。

(继承自 DataGridViewCell)
PaintErrorIcon(Graphics, Rectangle, Rectangle, String)

绘制当前 DataGridViewCell 的错误图标。

(继承自 DataGridViewCell)
ParseFormattedValue(Object, DataGridViewCellStyle, TypeConverter, TypeConverter)

将为便于显示而进行了格式设置的值转换为实际的单元格值。

(继承自 DataGridViewCell)
PositionEditingControl(Boolean, Boolean, Rectangle, Rectangle, DataGridViewCellStyle, Boolean, Boolean, Boolean, Boolean)

设置由 DataGridView 控件中的单元格承载的编辑控件的位置和大小。

(继承自 DataGridViewCell)
PositionEditingPanel(Rectangle, Rectangle, DataGridViewCellStyle, Boolean, Boolean, Boolean, Boolean)

设置单元格承载的编辑面板的位置和大小,并返回编辑面板内编辑控件的正常界限。

(继承自 DataGridViewCell)
RaiseCellClick(DataGridViewCellEventArgs)

引发 CellClick 事件。

(继承自 DataGridViewElement)
RaiseCellContentClick(DataGridViewCellEventArgs)

引发 CellContentClick 事件。

(继承自 DataGridViewElement)
RaiseCellContentDoubleClick(DataGridViewCellEventArgs)

引发 CellContentDoubleClick 事件。

(继承自 DataGridViewElement)
RaiseCellValueChanged(DataGridViewCellEventArgs)

引发 CellValueChanged 事件。

(继承自 DataGridViewElement)
RaiseDataError(DataGridViewDataErrorEventArgs)

引发 DataError 事件。

(继承自 DataGridViewElement)
RaiseMouseWheel(MouseEventArgs)

引发 MouseWheel 事件。

(继承自 DataGridViewElement)
SetValue(Int32, Object)

设置单元格的值。

(继承自 DataGridViewCell)
ToString()

返回描述当前对象的字符串。

适用于

另请参阅