【问题标题】:display images in datagrid with Compact Framework使用 Compact Framework 在数据网格中显示图像
【发布时间】:2009-06-09 13:02:39
【问题描述】:

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

有什么建议吗?

【问题讨论】:

    标签: compact-framework datagrid


    【解决方案1】:

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

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

    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,所以我可以指定我需要在这个类之外显示的图标。

    现在,要在 DataGrid 上实际使用它,您将有一个类似如下的 sn-p:

    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 的其余部分做了很多进一步的定制。但它应该让你开始你想做的事情。

    【讨论】:

    • 如果我需要在单元格中加载图像??我该怎么做?
    【解决方案2】:

    我知道如何做到这一点的唯一方法就是使用在网格上绘制一些图像的技巧来呈现网格中的文本框。

    CF team posted something about customising the grid on their site.之一

    【讨论】:

      【解决方案3】:

      【讨论】:

        【解决方案4】:

        如果您能够使用第三方解决方案,请查看 Resco SmartGrid

        【讨论】:

          【解决方案5】:

          http://www.cf-technologies.net/compactgrid.php。您可以使用单元格的 CustomDraw 事件..

          【讨论】:

            猜你喜欢
            • 2011-10-13
            • 2013-03-16
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-09-16
            • 1970-01-01
            • 2010-10-09
            相关资源
            最近更新 更多