首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

三个小疑点

2012-02-11 
三个小问题我在TstringGrid下实现以下结果:01时02时...08时文件101:0202:03...08:19文件201:1002:08...08:

三个小问题
我在TstringGrid下实现以下结果:
                    01时       02时   ...       08时              
文件1         01:02     02:03   ...     08:19  
文件2         01:10     02:08   ...     08:34
...             ...         ...       ...     ...
文件10       01:33     02:32   ...     08:12

作用是每小时都显示相应文件生成的时间,问题如下:
1.如何把大于30分钟的数据用红色显示;
2.能否通过点击 "01时 "(还有其他时间)弹出提示信息,统计超过30分的数据个数,显示 "超时个数:XX个 "
3.当8个小时结束,数据写满后,如何全部清除,然后从01重新开始?

[解决办法]
建议你还是找个TMS控件 用里面的TADVColumGrid来实现很方便
要变颜色直接有grid-> Colors[][]属性 其他的处理都很简单
[解决办法]
//---------------------------------------
#include <FileCtrl.hpp>
#include <fstream.h>
#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::Timer1Timer(TObject *Sender)
{
Timer1-> Enabled = false;
StringGrid1-> ColCount = StringGrid1-> ColCount + 1;
StringGrid1-> RowCount = 10;
for(int i = 0; i < 10; i++)
{
int col = StringGrid1-> ColCount - 1;
StringGrid1-> Cells[col][i] = Time();
String filename = Edit1-> Text + IntToStr(i) + ".txt ";
FileCreate(filename);
}
Timer1-> Enabled = true;
Timer2-> Enabled = true;
}
//---------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString Dir = " ";
if (SelectDirectory(Dir, TSelectDirOpts() < < sdAllowCreate < < sdPerformCreate < < sdPrompt,1000))
Label1-> Caption = Dir;

}
//---------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
StringGrid1-> ColCount = 1;
StringGrid1-> RowCount = 10;
Edit1-> Text = Application-> ExeName.SubString(1, Application-> ExeName.LastDelimiter( "\\ ") );
Timer1-> Interval = 3600000;
//Timer1-> Interval = 3;
Timer2-> Interval = 300000;
//Timer2-> Interval = 30;
StringGrid1-> RowCount = 10;
for(int i = 0; i < 10; i++)
{
int col = StringGrid1-> ColCount - 1;
StringGrid1-> Cells[col][i] = Time();
String filename = Edit1-> Text + IntToStr(i) + ".txt ";
//FileCreate(filename);
ofstream output;
output.open(filename.c_str(),ios::out);
output.close();
}
Timer1-> Enabled = true;


Timer2-> Enabled = true;
}
//---------------------------------------
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
Timer2-> Enabled = false;
for(int i = 0; i < 10; i++)
{
String filename = Edit1-> Text + IntToStr(i) + ".txt ";
DeleteFile(filename.c_str());
}
}
//---------------------------------------

[解决办法]
1.如何把大于30分钟的数据用红色显示;
可以用自绘的方法,建议用TListView有关他的自绘论坛有很多帖子
2.能否通过点击 "01时 "(还有其他时间)弹出提示信息,统计超过30分的数据个数,显示 "超时个数:XX个 "
TListView有列表头点击事件可以处理。
3.当8个小时结束,数据写满后,如何全部清除,然后从01重新开始?
直接清除Item

建议用控件更快捷。
[解决办法]
1.如何把大于30分钟的数据用红色显示;
2.能否通过点击 "01时 "(还有其他时间)弹出提示信息,统计超过30分的数据个数,显示 "超时个数:XX个 "
int xx = 0;
for(int j = 0; j < StringGrid1-> RowCount; j++)
{
String aa = StringGrid1-> Cells[1][j];
01:10
aa = aa.SubString(aa.Pos( ": ") + 1, aa.Length() - aa.Pos( ": ");
int bb = StrToInt(aa);
if(bb > 30)
{
xx++;
}
}
3.当8个小时结束,数据写满后,如何全部清除,然后从01重新开始?
for(int i = 0; i < StringGrid1-> CelCount; i++)
for(int j = 0; j < StringGrid1-> RowCount; j++)
StringGrid1-> Cells[i][j] = " ";
3.StringGrid1-> CelCount = 1;
StringGrid1-> RowCount = 1;

热点排行