第3课 使用( Get...Set ) 函数
来源:互联网 发布:沙驰皮鞋 知乎 编辑:程序博客网 时间:2024/06/10 02:43
操作某个单元格、标题或者一列,甚至是整个表格,方法就是使用 Get...Set 函数。当你需要操作单元格的时候,必须先用GetCell() 函数去获取单元格对象的拷贝,然后修改其属性(比如你可以改变某个单元格的背景色,或则修改其文字),最后使用SetCell()函数再写回单元格改变它。正确的语法如下所示:
2
3
4
5
6
7
8
9
10
11
12
13
14
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);
第1步 对单元格信息进行修改。
当我们用鼠标的左键单击一个单元格时,程序会调用消息响应函数。下面的例子展示了在OnLClicked()消息响应函数内使用GetCell()和SetCell()函数。
程序将完成如下功能,当我们用鼠标的左键点击单元格时,此单元格的背景色将改变成青色,并将文字"Ultimate Toolbox" 写在格内。
添加下列代码到 MyCue 类的 OnLClicked()函数中
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列为红色的背景和文字靠右对齐。
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
{
//****** 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() 函数修改其属性(比如文字、背景色等等)。
下列代码段使标题行与标题列为绿色的背景和文字竖直方向靠底边对齐。
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
{
//****** 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() 函数修改其属性(比如风格、背景色等等)。
下列代码段使表格的背景色为青色,单元格风格为边框突起。
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
{
//**** 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);
}
}
}
- 第3课 使用( Get...Set ) 函数
- set get函数
- 慎重使用Get/Set成员函数(二)Set函数和其他修改函数的替代办法
- C# get set 使用
- 慎重使用Get/Set成员函数(一)问题的提出
- 慎重使用Get/Set成员函数(三)Get函数替代办法-让类说话
- Matlab常用函数set&get
- get/set方法的使用
- 关于{Get;Set;}的使用
- c# 使用get set方法
- 简单使用set、get方法
- php set get方法使用
- c# get set使用心得
- 第26节 Get和Set方法
- Get/Set函数和public成员变量
- Get/Set函数和public成员变量
- Matlab GUI通用函数get和set
- 利用宏自动产生Get/Set函数
- centos虚拟机下联网
- 学习 Box2D 个人笔记(一)b2World
- 【shell】sed的-e选项
- Cocos2d-x 2.0变速动画深入分析
- VC2010工程中加入SplashScreen及原理释解
- 第3课 使用( Get...Set ) 函数
- Hibernate3.5.4---java application的xml和annotation环境搭建(hibernate.cfg.xml配置文件说明,映射文件Student.hbm.xml说明)
- php使用cookie
- java reflect 反射
- 习题9.38
- AC算法
- Oracle导入导出命令
- 苹果 助手
- test