UltraGrid单元格放多个图片

来源:互联网 发布:淘宝访客突然少了很多 编辑:程序博客网 时间:2024/06/07 03:10
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
原创粉丝点击