第4课 行列的尺寸、文本的对齐方式和字体的改变
来源:互联网 发布:多久修一次眉毛知乎 编辑:程序博客网 时间:2024/06/14 02:24
这一课演示如何改变行或列的尺寸以及单元格文字的对齐方式。通常,当我们把鼠标移动到标题行的分割线或标题列的分隔线时,光标会变成左右或上下两个箭头形状的光标,此时就可以拖动鼠标来改变行或列的尺寸。当然也可以对表格编程以使它的行或列尺寸不可改变。第3课已经介绍了改变单元格属性既可以采用Get...Set函数也可以采用QuickSet()函数,这部分用QuickSet()函数去改变单元格的对齐方式。
第1步 修改OnCanSizeCol()函数
在MyCug()类的OnCanSizeCol()函数中添加如下代码。这段代码将使得用户无法改变第三列的宽度(把鼠标移动到第3列的右边线,就是上标题中绿色的4和5中间的分割线时,会跳出一个警告框)。
C++ Code
2
3
4
5
6
7
8
9
10
11
int MyCug::OnCanSizeCol(int col)
{
UNREFERENCED_PARAMETER(col);
//****** Disallow column 3 from being resized
if (col == 3)
{
MessageBox("illegal Procedure!!- Column 3 cannot be resized", "Grid Error", MB_ICONSTOP);
return FALSE;
}
return TRUE;
}
{
UNREFERENCED_PARAMETER(col);
//****** Disallow column 3 from being resized
if (col == 3)
{
MessageBox("illegal Procedure!!- Column 3 cannot be resized", "Grid Error", MB_ICONSTOP);
return FALSE;
}
return TRUE;
}
第2步 修改OnCanSizeRow()函数
在MyCug()类的OnCanSizeRow()函数中添加如下代码。这段代码将使得用户无法改变第2行的高度(把鼠标移动到第2行的下边线,就是左标题中绿色的3和4中间的分割线时,会跳出一个警告框)。
C++ Code
2
3
4
5
6
7
8
9
10
11
int MyCug::OnCanSizeRow(long row)
{
UNREFERENCED_PARAMETER(row);
if (row == 2)
{
//****** Disallow row 2 from being resized
MessageBox("Illegal Procedure -- Row 2 cannot be resized.", "Grid Error", MB_ICONSTOP);
return FALSE;
}
return TRUE;
}
{
UNREFERENCED_PARAMETER(row);
if (row == 2)
{
//****** Disallow row 2 from being resized
MessageBox("Illegal Procedure -- Row 2 cannot be resized.", "Grid Error", MB_ICONSTOP);
return FALSE;
}
return TRUE;
}
第3步 改变表格文本对齐方式。
文本有好多种对齐方式(左对齐、右对齐、上对齐等等)。这里举例使用UG_ALIGNVCENTER(水平居中)。在MyCug()类中的OnSetup()函数中添加如下代码
C++ Code
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
//******* Declare all variables
int index , num_cols, num_rows;
CUGCell cell;
CString heading, number;
//****** Set the Rows and Columns
SetNumberCols(10);
SetNumberRows(10) ;
//******* Get the number of rows and columns
num_rows = GetNumberRows();
num_cols = GetNumberCols();
//****** Set the column headings
for (index = 0; index < num_rows; index++)
{
heading.Format("%d", index + 1);
QuickSetText(-1, index, heading);
QuickSetAlignment(-1, index, UG_ALIGNCENTER );
}
//******* Set the row headings
for (index = 0; index < num_cols; index++)
{
heading.Format("%d", index + 1);
QuickSetText(index, -1, heading);
QuickSetAlignment(index, -1, UG_ALIGNCENTER );
}
//******* Set the multiplication table
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_ALIGNCENTER );
}
}
int index , num_cols, num_rows;
CUGCell cell;
CString heading, number;
//****** Set the Rows and Columns
SetNumberCols(10);
SetNumberRows(10) ;
//******* Get the number of rows and columns
num_rows = GetNumberRows();
num_cols = GetNumberCols();
//****** Set the column headings
for (index = 0; index < num_rows; index++)
{
heading.Format("%d", index + 1);
QuickSetText(-1, index, heading);
QuickSetAlignment(-1, index, UG_ALIGNCENTER );
}
//******* Set the row headings
for (index = 0; index < num_cols; index++)
{
heading.Format("%d", index + 1);
QuickSetText(index, -1, heading);
QuickSetAlignment(index, -1, UG_ALIGNCENTER );
}
//******* Set the multiplication table
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_ALIGNCENTER );
}
}
(数据都水平居中了)
第4步 改变表格中文字的字体
这个例子演示了如何改变字体风格(25pt 大小的"Arial Bold Italic" 字体)。添加下列代码到MyCug()类的OnSetup()函数中。
C++ Code
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
void MyCug::OnSetup()
{
//******* Declare all variables
int index , num_cols, num_rows;
CUGCell cell;
CString heading, number;
//****** Set the Rows and Columns
SetNumberCols(10);
SetNumberRows(10) ;
//******* Get the number of rows and columns
num_rows = GetNumberRows();
num_cols = GetNumberCols();
//****** Set the column headings
for (index = 0; index < num_rows; index++)
{
heading.Format("%d", index + 1);
QuickSetText(-1, index, heading);
QuickSetAlignment(-1, index, UG_ALIGNCENTER );
}
//******* Set the row headings
for (index = 0; index < num_cols; index++)
{
heading.Format("%d", index + 1);
QuickSetText(index, -1, heading);
QuickSetAlignment(index, -1, UG_ALIGNCENTER );
}
//******* Set the multiplication table
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_ALIGNCENTER );
}
}
//***** Create a new Font
int fontIndex = AddFont("Arial Bold Italic", 25, 2);
//****** Create a CFont pointer
CFont *myFont;
//****** Populate the CFont Pointer
myFont = GetFont(fontIndex);
//****** Set the font to column 0
GetColDefault(0, &cell);
cell.SetFont(myFont);
SetColDefault(0, &cell);
}
{
//******* Declare all variables
int index , num_cols, num_rows;
CUGCell cell;
CString heading, number;
//****** Set the Rows and Columns
SetNumberCols(10);
SetNumberRows(10) ;
//******* Get the number of rows and columns
num_rows = GetNumberRows();
num_cols = GetNumberCols();
//****** Set the column headings
for (index = 0; index < num_rows; index++)
{
heading.Format("%d", index + 1);
QuickSetText(-1, index, heading);
QuickSetAlignment(-1, index, UG_ALIGNCENTER );
}
//******* Set the row headings
for (index = 0; index < num_cols; index++)
{
heading.Format("%d", index + 1);
QuickSetText(index, -1, heading);
QuickSetAlignment(index, -1, UG_ALIGNCENTER );
}
//******* Set the multiplication table
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_ALIGNCENTER );
}
}
//***** Create a new Font
int fontIndex = AddFont("Arial Bold Italic", 25, 2);
//****** Create a CFont pointer
CFont *myFont;
//****** Populate the CFont Pointer
myFont = GetFont(fontIndex);
//****** Set the font to column 0
GetColDefault(0, &cell);
cell.SetFont(myFont);
SetColDefault(0, &cell);
}
- 第4课 行列的尺寸、文本的对齐方式和字体的改变
- Android改变文本的字体
- css的字体和尺寸
- android textview等文本内容中字体颜色的改变和字体背景色的改变
- Excel操作——单元格的字体和对齐方式
- Excel操作——单元格的字体和对齐方式
- 改变个别字体颜色的富文本
- 设置UIButton上字体的对齐方式
- 设置UIButton上字体的对齐方式
- UIButton上字体的对齐方式
- 可调整标签文本对齐方式的群组框
- CRichEditView改变字体的颜色和字体
- Mac改变launch的行列
- 结构体对齐的方式(自动对齐和手动对齐)
- ios开发之改变UIWebView文本字体的样式和大小
- ios开发之改变UIWebView文本字体的样式和大小
- IOS开发之改变UIWebView文本字体的样式和大小
- IOS开发之改变UIWebView文本字体的样式和大小
- Android数据库
- 铁道部12306后台技术框架、完整异常栈信息以及技术缺点和漏洞
- mini2440插入usb设备出现: unable to enumerate USB device on port问题的解决,以及使用super vivi对nand flash进行分区
- android 参数共享
- 用TCL分配管脚的方法
- 第4课 行列的尺寸、文本的对齐方式和字体的改变
- CF 149E Martian Strings(KMP)
- 探讨C语言中的回调函数
- Eclipse插件的安装
- android参数共享
- ARM中断方式理解(2)
- linux下生成core dump文件方法及设置
- Linux core dump详解
- 好用的vim配置