compact-framework - 使用 Compact Framework 在数据网格中显示图像

标签 compact-framework datagrid

是否可以在数据网格单元格中显示图像?
我目前正在使用紧凑型框架 3.5。

有什么建议吗?

最佳答案

就像其他海报评论的那样,你需要自己动手。幸运的是,这并不太难。

在我的应用程序中,我需要一种在特定列中绘制 16x16 图标的方法。我创建了一个继承自 DataGridColumnStyle 的新类,这使得申请 DataGrid 变得容易通过 DataGridTableStyle目的。

class DataGridIconColumn : DataGridColumnStyle {

public Icon ColumnIcon {
    get;
    set;
}

protected override void Paint( Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight ) {

    // Fill in background color
    g.FillRectangle( backBrush, bounds );

    // Draw the appropriate icon
    if (this.ColumnIcon != null) {
        g.DrawIcon( this.ColumnIcon, bounds.X, bounds.Y );
    }
  }
}

可以看到我定义了公共(public)属性ColumnIcon所以我可以指定我需要在这个类之外显示的图标。

现在,要在 DataGrid 上实际使用它,您将有如下代码片段:
DataGridTableStyle ts = new DataGridTableStyle();

DataGridIconColumn dgic = new DataGridIconColumn();
dgic.ColumnIcon = Properties.Resources.MyIcon;
dgic.MappingName = "<your_column_name>";
dgic.HeaderText = "<your_column_header>";

ts.GridColumnStyles.Add(dgic);

this.myDataGrid.TableStyles.Add( ts );

这是应用 DataGridTableStyle 的一个非常简单的示例。 -- 实际上我对我的 DataGrid 的其余部分做了很多进一步的定制。列。但它应该让你开始你想做的事情。

关于compact-framework - 使用 Compact Framework 在数据网格中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/969937/

相关文章:

c# - 适用于 Windows 和 Windows Mobile 的通用 C# 源代码

c# - 在 .net Compact Framework 中使用 WEB API 身份验证

php - 我如何自定义 Yii2 gridview 排序?

c# - 如何对我的数据网格表进行排序

php - 在 Magento 中向客户网格添加列 - 数据未填充

c# - Datagrid 按需卸载

c# - 在 Compact Framework 中使用 WCF 错误

c# - Web 服务在第一次尝试时未连接

c# - Hook API 函数 GetSystemMetrics

c# - WPF DataGrid - 将源和宽度绑定(bind)到不同的对象