C++ Builder之StringGrid表格简单示例(TStringGrid控件实例例子)
2022/1/7 9:03:33
本文主要是介绍C++ Builder之StringGrid表格简单示例(TStringGrid控件实例例子),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
程序运行截图如下:
每次点击可以生成不同的成绩表。
主要源代码如下:
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; AnsiString columns[]={"姓名","语文","数学","英语","计算机"}; AnsiString names[]={"王小明","李小刚","陈大海","林小芳","张小静","杨光"}; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { this->Caption="StringGrid表格简单示例"; StringGrid1->ColCount=sizeof(columns)/sizeof(AnsiString); StringGrid1->RowCount=1+sizeof(names)/sizeof(AnsiString); for(int x=0;x<StringGrid1->ColCount;++x) { StringGrid1->Cells[x][0]=columns[x]; } for(int y=1;y<StringGrid1->RowCount;++y) { StringGrid1->Cells[0][y]=names[y-1]; } srand((unsigned)time(NULL)); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { for(int x=1;x<StringGrid1->ColCount;++x) { for(int y=1;y<StringGrid1->RowCount;++y) { int score=60+rand()%41; StringGrid1->Cells[x][y]=IntToStr(score); } } } //---------------------------------------------------------------------------
这篇关于C++ Builder之StringGrid表格简单示例(TStringGrid控件实例例子)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-04el-table 开启定时器下,表格的选中状态会消失是什么原因-icode9专业技术文章分享
- 2024-10-03如何安装和初始化飞牛私有云 fnOS?-icode9专业技术文章分享
- 2024-10-03如何安装 App 并连接到飞牛 NAS?-icode9专业技术文章分享
- 2024-10-03如何安装飞牛 TV 并连接到影视服务器?-icode9专业技术文章分享
- 2024-10-03如何在PVE和ESXI上安装飞牛私有云 fnOS?-icode9专业技术文章分享
- 2024-10-03fnOS国产最强NAS安装系统异常情况处理-icode9专业技术文章分享
- 2024-10-03飞牛NAS如何创建存储空间?-icode9专业技术文章分享
- 2024-10-03fnOS国产最强NAS硬盘会自动休眠吗?-icode9专业技术文章分享
- 2024-10-03fnOS国产最强NAS如何安装飞牛影视和创建媒体库?-icode9专业技术文章分享
- 2024-10-03fnOS国产最强NAS如何为家人朋友开通影视账号?-icode9专业技术文章分享