UltraGrid单元格放多个图片
2014-01-02 19:33
316 查看
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; }
相关文章推荐
- BeautyEye主题使用中BETitlePane的标题栏图标按钮个性修改
- SharePoint 2013 自定义翻页显示列表项
- C++ arraylist实现
- Linq学习__05__查询表达式和方法查询比较
- uva 755 - 487--3279
- amazon s3 的用户验证 access-key, secrete-key
- windows远程连接Linux的两个小工具
- Android中SQLiite的replace、update、insert以及表级和字段级冲突解决
- Linq学习__04__数据源是XML
- System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)
- Windows下Memcached安装与配置实例
- 人头检测代码示例:SVM+HOG
- Entity FrameWork 中使用Lambda访问数据库性能优化
- pgsql 安装详解
- 项目视频讲解_[HeyJava][尚学堂][CMS文章内容管理系统]
- java中的各种数据类型在内存中存储的方式
- VirtualBox 4.3.6 编译 for 64bit Windows
- 《对不起,只能把你锁在记忆里》
- 清理数据库中对应某个字段的所有非法数据的一种解决方案 SQL语句
- 解决/usr/bin/ld: cannot find -lxxx