13,826
社区成员
发帖
与我相关
我的任务
分享
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{ ComboBox1->Items->Add("所有借阅记录");
ComboBox1->Items->Add("今日借阅记录");
ComboBox1->Items->Add("今日到期记录");
ComboBox1->Items->Add("已经过期记录");
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{ AnsiString a="资料编号",b="好好学习",c="天天向上",d="你好";
AnsiString e;
StringGrid1->Align=alTop;
StringGrid1->RowCount=5;
StringGrid1->ColCount=5;
//StringGrid1->FixedRows=1;
//StringGrid1->FixedCols=1;
StringGrid1->FixedColor=clGray;
for(int i=1;i<5;i++)
{
StringGrid1->Cells[i][0]=IntToStr(i);
StringGrid1->Cells[0][i]=IntToStr(i);
}
if(ComboBox1->SelText=="所有借阅记录")
{e=a;}
else if(ComboBox1->SelText=="今日借阅记录")
{e=b;}
else if(ComboBox1->SelText=="今日到期记录")
{e=c;}
else if (ComboBox1->SelText=="已经过期记录")
{e=d;}
for(int i=2;i<6;i++)
{
for(int j=2;j<6;j++)
{
StringGrid1->Cells[i][j]=e;
}
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Grids.hpp>
const AnsiString a[]={"资料编号","好好学习","天天向上","你好"};
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TComboBox *ComboBox1;
TButton *Button1;
TStringGrid *StringGrid1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString a[]={"资料编号","好好学习","天天向上","你好"};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
StringGrid1->RowCount=5;
StringGrid1->ColCount=5;
//StringGrid1->FixedRows=1;
//StringGrid1->FixedCols=1;
StringGrid1->FixedColor=clGray;
for(int i=1;i<5;i++)
{
StringGrid1->Cells[i][0]=IntToStr(i);
StringGrid1->Cells[0][i]=IntToStr(i);
}
ComboBox1->Items->Add("所有借阅记录");
ComboBox1->Items->Add("今日借阅记录");
ComboBox1->Items->Add("今日到期记录");
ComboBox1->Items->Add("已经过期记录");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i=ComboBox1->ItemIndex;
Caption=IntToStr(i); //测试用
if(i<0) //i==-1
{
ShowMessage("下拉列表请选择一项");
}
else
{
AnsiString s;
if(i<sizeof(a)/sizeof(AnsiString)) //确保下拉列表选项不超过数组a的项目
s=a[i]; //避免数组越界
else
s="未定义";
for(int x=1;x<5;x++)
for(int y=1;y<5;y++)
//Cells[列][行],因为列为x,行为y,与二维数组不同
//比如MouseToCell(X, Y, Column, Row)
StringGrid1->Cells[x][y]=s;
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString a[]={"资料编号","好好学习","天天向上","你好"};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
StringGrid1->RowCount=5;
StringGrid1->ColCount=5;
//StringGrid1->FixedRows=1;
//StringGrid1->FixedCols=1;
StringGrid1->FixedColor=clGray;
for(int i=1;i<5;i++)
{
StringGrid1->Cells[i][0]=IntToStr(i);
StringGrid1->Cells[0][i]=IntToStr(i);
}
ComboBox1->Items->Add("所有借阅记录");
ComboBox1->Items->Add("今日借阅记录");
ComboBox1->Items->Add("今日到期记录");
ComboBox1->Items->Add("已经过期记录");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i=ComboBox1->ItemIndex;
Caption=IntToStr(i); //测试用
if(i<0) //i==-1
{
ShowMessage("下拉列表请选择一项");
}
else
{
AnsiString s=a[i];
for(int x=1;x<5;x++)
for(int y=1;y<5;y++)
//Cells[列][行],因为列为x,行为y,与二维数组不同
//比如MouseToCell(X, Y, Column, Row)
StringGrid1->Cells[x][y]=s;
}
}
//---------------------------------------------------------------------------
初始化(只执行一次)的代码一般都可以放在构造函数里,有的可以在OnCreate里。
for(int i=2;i<6;i++) 是错的,数组 a[n] 完整下标都是从0 ~ n-1,而不是1~n