使用Compact Framework在datagrid中显示图像 [英] display images in datagrid with Compact Framework

查看:97
本文介绍了使用Compact Framework在datagrid中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

is it possible to display an image in a datagrid cell? i'm currently working with compact framework 3.5.

任何提示?

推荐答案

像其他海报已经评论过,你需要自己滚动。幸运的是,这不是太难了。

Like the other posters have commented, you're required to roll your own. Luckily, this isn't too difficult.

在我的应用程序中,我需要一种在特定列中绘制16x16图标的方法。我创建了一个继承自 DataGridColumnStyle 的新类,可以轻松地通过<$ c应用于 DataGrid $ c> DataGridTableStyle 对象

In my application, I needed a way to draw a 16x16 icon in a particular column. I created a new class that inherits from DataGridColumnStyle, which makes it easy to apply to a DataGrid via a DataGridTableStyle object.

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 );
    }
  }
}

你可以看到我定义公共财产 ColumnIcon 所以我可以指定我需要显示在这个课外的图标。

You can see that I defined the public property ColumnIcon so I can specify the icon I need to display outside of this class.

现在,到实际上使用它在一个DataGrid,你会有一个这样的代码片段:

Now, to actually use it on a DataGrid, you'd have a snippet like:

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 列进行了许多进一步的定制。但是,应该让你开始你想做的事。

That's a pretty simple example for applying the DataGridTableStyle -- I actually do a lot of further customization on the rest of my DataGrid columns. But it should get you started on what you want to do.

这篇关于使用Compact Framework在datagrid中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆