UltraGrid单元格放多个图片

private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
{
    // Get the images that we might want to show in the cell.
    // You could optimize this method by caching the Bitmaps as members of the class.
    using( Bitmap bmp1 = new Bitmap( @"..\..\squiggle_up.bmp" ) )
    using( Bitmap bmp2 = new Bitmap( @"..\..\arrow_up.bmp" ) )
    using( Bitmap bmp3 = new Bitmap( @"..\..\squiggle_down.bmp" ) )
    using( Bitmap bmp4 = new Bitmap( @"..\..\arrow_down.bmp" ) )
    {
        Bitmap[] bmps;
        // Using whatever conditions you need, populate the array of Bitmaps
        // with the appropriate images. For this simple demo, we determine
        // the images to use based on the customer ID field.
        int custID = (int)e.Row.Cells[ "custID" ].Value;
        if( custID < 1 )
            bmps = new Bitmap[]{};
        else if( custID == 1 )
            bmps = new Bitmap[]{ bmp1 };
        else if( custID == 2 )
            bmps = new Bitmap[]{ bmp1, bmp2 };
        else if( custID == 3 )
            bmps = new Bitmap[]{ bmp1, bmp2, bmp3 };
        else
            bmps = new Bitmap[]{ bmp1, bmp2, bmp3, bmp4 };
        // If we have already given this cell a Bitmap, dispose of it before reassigning the new Bitmap.
        if( e.ReInitialize )
            ((Bitmap)e.Row.Cells["images"].Value).Dispose();
        // Pass the array of Bitmaps into the helper method which will
        // combine all of the images into one. Then assign that new image
        // to the value of the cell.
        e.Row.Cells["images"].Value = CombineBitmaps( bmps );
    }
}
private Bitmap CombineBitmaps( Bitmap[] bitmaps )
{            
    if( bitmaps.Length == 0)
        return new Bitmap( 1, 1 );
    int width = 0;
    int height = 0;
    foreach( Bitmap bmp in bitmaps )
    {
        width += bmp.Width;
        if( height < bmp.Height )
            height = bmp.Height;
    }
    Bitmap bitmap = new Bitmap( width, height );    
    using( Graphics grfx = Graphics.FromImage( bitmap ) )
    {
        int x = 0;
        foreach( Bitmap bmp in bitmaps )
        {            
            grfx.DrawImage( bmp, x, 0, bmp.Width, height );
            x += bmp.Width;
        }
    }
    return bitmap;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值