第3课 使用( Get...Set ) 函数
2012-12-26 13:16
281 查看
操作某个单元格、标题或者一列,甚至是整个表格,方法就是使用 Get...Set 函数。当你需要操作单元格的时候,必须先用GetCell() 函数去获取单元格对象的拷贝,然后修改其属性(比如你可以改变某个单元格的背景色,或则修改其文字),最后使用SetCell()函数再写回单元格改变它。正确的语法如下所示:
C++ Code
第1步 对单元格信息进行修改。
当我们用鼠标的左键单击一个单元格时,程序会调用消息响应函数。下面的例子展示了在OnLClicked()消息响应函数内使用GetCell()和SetCell()函数。
程序将完成如下功能,当我们用鼠标的左键点击单元格时,此单元格的背景色将改变成青色,并将文字"Ultimate Toolbox" 写在格内。
添加下列代码到 MyCue 类的 OnLClicked()函数中
C++ Code
下面是运行结果:
![](http://img.my.csdn.net/uploads/201212/25/1356440211_8212.JPG)
第2步 对某一列的默认参数进行修改。
可以使用 GetColDefault() 函数指定某一列,然后再用 SetColDefault() 函数修改这一列的属性(比如文字、背景色等等)。
下列代码段使第0列为红色的背景和文字靠右对齐。
C++ Code
![](http://img.my.csdn.net/uploads/201212/26/1356492537_2961.JPG)
第3步 设置表格标题行与标题列的默认属性。
可以使用 GetHeadingDefault() 函数获得将要进行操作的标题行与标题列,然后再用 SetHeadingDefault() 函数修改其属性(比如文字、背景色等等)。
下列代码段使标题行与标题列为绿色的背景和文字竖直方向靠底边对齐。
C++ Code
![](http://img.my.csdn.net/uploads/201212/26/1356500339_5488.JPG)
第4步 对表格默认属性进行修改。
可以使用GetGridDefault() 函数获得整个表格,然后再用 SetGridDefault() 函数修改其属性(比如风格、背景色等等)。
下列代码段使表格的背景色为青色,单元格风格为边框突起。
C++ Code
C++ Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | //******* Create a CUGCell object CUGCell cell; //******* Get cell 1,1 GetCell(1, 1, &cell); //******** Amend the cell properties cell.SetText("Ultimate Toolbox"); cell.SetAlignment(UG_ALIGNTOP); //****** Set 3 cells SetCell(1, 1, &cell); SetCell(2, 1, &cell); SetCell(3, 1, &cell); |
当我们用鼠标的左键单击一个单元格时,程序会调用消息响应函数。下面的例子展示了在OnLClicked()消息响应函数内使用GetCell()和SetCell()函数。
程序将完成如下功能,当我们用鼠标的左键点击单元格时,此单元格的背景色将改变成青色,并将文字"Ultimate Toolbox" 写在格内。
添加下列代码到 MyCue 类的 OnLClicked()函数中
C++ Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /*****************************************************************/ void MyCug::OnLClicked(int col, long row, int updn, RECT *rect, POINT *point, int processed) { //******* Declare all Variables CString message = "Ultimate Toolbox"; CUGCell cell; //******* Amend the cell using 'Get..Set' GetCell(col, row, &cell); cell.SetBackColor(RGB(0, 255, 255)); cell.SetText(message); SetCell(col, row, &cell); RedrawCell(col, row); } |
第2步 对某一列的默认参数进行修改。
可以使用 GetColDefault() 函数指定某一列,然后再用 SetColDefault() 函数修改这一列的属性(比如文字、背景色等等)。
下列代码段使第0列为红色的背景和文字靠右对齐。
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 | void MyCug::OnSetup() { //****** Declare all variables CString heading, number; int num_rows, num_cols; CUGCell cell; //****** 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 (int index = 0; index < num_rows; index++) { heading.Format("%d", index + 1); QuickSetText(-1, index, heading); } //****** Add the Column Heading to the grid for (index = 0; index < num_cols; index++) { heading.Format("%d", index + 1); QuickSetText(index, -1, heading); } //***** Add the Multiplication table to 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); } } //*******Set a Default style to column 0 GetColDefault(0, &cell); cell.SetBackColor(RGB(255, 0, 0)); cell.SetAlignment(UG_ALIGNRIGHT); SetColDefault(0, &cell); } |
第3步 设置表格标题行与标题列的默认属性。
可以使用 GetHeadingDefault() 函数获得将要进行操作的标题行与标题列,然后再用 SetHeadingDefault() 函数修改其属性(比如文字、背景色等等)。
下列代码段使标题行与标题列为绿色的背景和文字竖直方向靠底边对齐。
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 CString heading, number; int num_rows, num_cols; CUGCell cell ; //****** 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 (int index = 0; index < num_rows; index++) { heading.Format("%d", index + 1); QuickSetText(-1, index, heading); } //****** Add the Column Heading to the grid for (index = 0; index < num_cols; index++) { heading.Format("%d", index + 1); QuickSetText(index, -1, heading); } //***** Add the Multiplication table to 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); } } //******* Create a CFont pointer CFont *myFont; //******* create the font index variable int fontIndex ; //****** Get the font index fontIndex = AddFont); //******* Populate the CFont pointer myFont = GetFont(fontIndex); //******** Set the Heading Default GetHeadingDefault(&cell); cell.SetFont(myFont); cell.SetAlignment(UG_ALIGNBOTTOM); cell.SetBackColor(RGB(0, 255, 0)); SetHeadingDefault(&cell); } |
第4步 对表格默认属性进行修改。
可以使用GetGridDefault() 函数获得整个表格,然后再用 SetGridDefault() 函数修改其属性(比如风格、背景色等等)。
下列代码段使表格的背景色为青色,单元格风格为边框突起。
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 | void MyCug::OnSetup() { //**** Declare all variables CUGCell cell ; CString buf, number; //****** Define the Grid Default GetGridDefault(&cell); cell.SetBorder(UG_BDR_RAISED); cell.SetBackColor(RGB(0, 255, 255)); SetGridDefault(&cell); //****** Set the number of rows and columns SetNumberCols(10); SetNumberRows(10); //****** Get the number of rows and columns int numRows = GetNumberRows(); int numCols = GetNumberCols(); //******* Add the top heading for (int xx = 0; xx < numCols; xx++) { buf.Format("%d", xx + 1); QuickSetText(xx, -1, buf); } //****** Add the side heading for (int zz = 0; zz < numRows; zz++) { buf.Format("%d", zz + 1); QuickSetText(-1, zz, buf); } //***** Add the multiplication table to the grid for (int x = 0; x < numCols; x++) { for(int z = 0; z < numRows; z++) { number.Format("%d", ((x + 1) * (z + 1))); QuickSetText(x, z, number); } } } |
相关文章推荐
- 慎重使用Get/Set成员函数(三)Get函数替代办法-让类说话
- 创建虚拟桌面的代码(重启桌面进程)(使用GetThreadDesktop,CreateDesktop,SetThreadDesktop等函数)
- 慎重使用Get/Set成员函数(二)Set函数和其他修改函数的替代办法
- C语言中settimeofday函数和gettimeofday函数的使用
- 慎重使用Get/Set成员函数(四)CSample可以被其他类做为返回值
- Linux下 getsockopt/setsockopt 函数使用说明
- 慎重使用Get/Set成员函数(一)问题的提出
- 使用'VRM_SET_VALUES'函数创建下拉列表
- idea中使用lombok,简化get和set方法的生成
- JAVA中关于set()和get()方法的理解及使用
- category使用 objc_setAssociatedObject/objc_getAssociatedObject 实现添加属性
- vb.net C# AtlAxGetControl 函数使用方法
- PHP __set(),__get(),isset(),unset()函数
- 如何在C#中使用get及set方法定义属性
- linux C getchar函数使用 笔记
- Matlab GUI通用函数get和set
- Android Studio的使用(四)--生成Get、Set方法
- SetThreadAffinityMask 函数使用慎重
- 【转】Linux时间函数之gettimeofday()函数之使用方法