这部分演示如何把数据放入网格内。
第1步 添加网格行和列的标题
在 MyCug 类的 OnSetup() 函数中添加编辑为如下代码:
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 | void MyCug::OnSetup() { //****** Declare all variables CString heading; int num_rows, num_cols, index; //****** Set the Rows and Columns SetNumberCols( 10 ); SetNumberRows( 10 ); //****** Get the number of rows and columns num_rows = GetNumberRows(); num_cols = GetNumberCols(); //******* Add the Row Heading to the grid for (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); } } |
第2步 把乘法表置入网格中
在 MyCug 类的 OnSetup() 函数中添加编辑为如下代码:
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 | void MyCug::OnSetup() { //****** Declare all variables CString heading, number; int num_rows, num_cols, index; //****** 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); } //****** 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); } } } |
编译 运行