本课演示在合并单元格中插入图片。这些特性对于开发电子表格或日历等程序都很有用。
第1步 建一个大单元格
在MyCug::OnSetup()函数中先调用EnableJoins()函数激活合并功能,再对单元格进行合并,再按要求处理合并了的单元格。代码如下:
EnableJoins(TRUE);
JoinCells(1,1,2,4); //把第1列第1行 到 第2列第4行 合并
第2步 添加图片到表格
在已经合并的单元格中添加文件名为dundas.bmp的图片。首先调用AddBitmap()函数读取图片文件,返回一个整型类型的值写入变量bitmap_index中,然后调用QuickSetBitmap()函数添加到合并的单元格中,此函数的第3个参数为变量bitmap_index。(随便找两张bmp图片,分别把名字改成dundas.bmp和toolbox.bmp放到项目目录下d:\ug\test),代码如下:
C++ Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
void
MyCug::OnSetup() { //******* Declare all variables int index , num_cols, num_rows; CUGCell cell; CString heading, number;; //******* Enable the Menu EnableMenu(TRUE); //****** Set the Rows and Columns SetNumberCols(10 ); SetNumberRows(10 ) ; //****** Get the Number of Rows and Columns num_rows = GetNumberRows(); num_cols = GetNumberCols(); //******* Add Row Heading to the grid for (index = 0 ; index < num_rows; index++) { heading.Format("%d", index + 1 ); QuickSetText(-1 , index, heading); QuickSetAlignment(-1 , index, UG_ALIGNVCENTER ); } //****** Add the Side headings to the grid for (index = 0 ; index < num_cols; index++) { heading.Format("%d", index + 1 ); QuickSetText(index, -1 , heading); QuickSetAlignment(index, -1 , UG_ALIGNVCENTER ); } //******* Populate the grid for (int x = 0 ; x < num_cols; x++) { for(int z = 0 ; z < num_rows; z++) { number.Format("%d", ((x + 1) * (z + 1 ))); QuickSetText(x, z, number); QuickSetAlignment(x, z, UG_ALIGNVCENTER ); } } //********** Join Cells Together EnableJoins(TRUE); JoinCells(1, 1, 2, 4 ); JoinCells(4, 1, 5, 6 ); //******* Add the Dundas Bitmap int bitmap_index = AddBitmap("dundas.bmp" ); QuickSetBitmap(1, 1 , bitmap_index); //******* Add another bitmap called toolbox int another_bitmap = AddBitmap("toolbox.bmp" ); QuickSetBitmap(4, 1 , another_bitmap); } |