如何给StringGrid的一行着色?

Greg_han 2008-09-21 04:33:05
我想给5行5列的StringGrid着色。第一行着 红色的
我的的程序如下:(运行有误)

void __fastcall TfrmCrossroadOutTable::StringGrid1DrawCell(TObject *Sender,
int ACol, int ARow, TRect &Rect, TGridDrawState State)
{
if(ARow==1)
{
StringGrid1->Canvas->Font->Color=clRed;
StringGrid1->Canvas->Font->Style=TFontStyles()<<fsBold;//使字体变粗

for(int i=1;i<=5;i++) //第一行
DrawText(StringGrid1->Canvas->Handle,
StringGrid1->Cells[1][i].c_str(),-1,
(RECT*)&Rect,DT_SINGLELINE);
}

请帮我看看如何改?
谢谢!!!!!
...全文
128 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
御剑逍遥恪 2008-09-23
  • 打赏
  • 举报
回复
if(ARow==7)
{
this->StringGrid1->Canvas->Brush->Color=RGB(34,120,100);
this->StringGrid1->Canvas->FillRect(Rect);
this->StringGrid1->Canvas->Font->Color=RGB(12,189,244);
this->StringGrid1->Canvas->TextOutA(Rect.Left+3,Rect.Top+3,"颜色字段");
}
给第7行着色~~ 以测试过~~
痞子酷 2008-09-22
  • 打赏
  • 举报
回复
接分
Greg_han 2008-09-22
  • 打赏
  • 举报
回复
谢谢 你们,加分 !!!!!
御剑逍遥恪 2008-09-22
  • 打赏
  • 举报
回复
详细
http://topic.csdn.net/t/20010709/20/187736.html
御剑逍遥恪 2008-09-22
  • 打赏
  • 举报
回复
在FormPaint中加入(在其他加,有错):
((TInplaceEdit*)StringGrid1->Components[0])->Brush->Color=clYellow;
(clYellow,你喜欢的颜色)


其实,TStringGrid中,当输入时,会有一个TInplaceEdit类产生,
将他的Brush->Color改变,就行了....

bob008 2008-09-21
  • 打赏
  • 举报
回复
接分...
bob008 2008-09-21
  • 打赏
  • 举报
回复
万恶的大小写... 讨厌的-> <<
写特
bob008 2008-09-21
  • 打赏
  • 举报
回复

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if (ARow==1)
{
StringGrid1->Canvas->Font->Color=clRed;
StringGrid1->Canvas->Font->Style=TFontStyles()<<fsBold;//使字体变粗
DrawText(StringGrid1->Canvas->Handle,StringGrid1->Cells[ACol][ARow].c_str(),-1,(RECT*)&Rect,DT_LEFT);
} else
{
StringGrid1->Canvas->Font->Color=clBlack;
StringGrid1->Canvas->Font->Style<<fsItalic;
DrawText(StringGrid1->Canvas->Handle,StringGrid1->Cells[ACol][ARow].c_str(),-1,(RECT*)&Rect,DT_LEFT);
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::StringGrid1Click(TObject *Sender)
{
ShowMessage(IntToStr(StringGrid1->Col)+IntToStr(StringGrid1->Row));
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
StringGrid1->Rows[1]->Append("aaaaa");
StringGrid1->Rows[1]->Append("aaaaa");
StringGrid1->Rows[1]->Append("aaaaa");
StringGrid1->Rows[1]->Append("aaaaa");
StringGrid1->Rows[1]->Append("aaaaa");
StringGrid1->Rows[2]->Append("aaaaa");
StringGrid1->Rows[2]->Append("aaaaa");
StringGrid1->Rows[2]->Append("aaaaa");
StringGrid1->Rows[2]->Append("aaaaa");
}
//---------------------------------------------------------------------------
Greg_han 2008-09-21
  • 打赏
  • 举报
回复
???
bob008 2008-09-21
  • 打赏
  • 举报
回复
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if(ARow==1)
{
StringGrid1->Canvas->Font->Color=clRed;
StringGrid1->Canvas->Font->Style=TFontStyles()<<fsBold;//使字体变粗

//第一行
for(int i=1;i<=5;i++)
{
DrawText(StringGrid1->Canvas->Handle,"hahaha",-1,(RECT*)&Rect,DT_LEFT);
}
}
}
你的StringGrid1->Cell[1][j].c_str() 压根什么都没有...
好了

字体着色OK了
Greg_han 2008-09-21
  • 打赏
  • 举报
回复
对不起,我说的 就是对第一行的 字体着色!
怎么办?
xabcxyz 2008-09-21
  • 打赏
  • 举报
回复
同意楼上
柯本 2008-09-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bob008 的回复:]
fillrect应该能满足你的要求...请放在DRAWTEXT前
[/Quote]
没错,你上面的程序是改字体色,这个是改CELL的色:
if(ARow==1)
{
// StringGrid1->Canvas->Font->Color=clRed;
StringGrid1->Canvas->Font->Style=TFontStyles() <<fsBold;//使字体变粗
StringGrid1->Canvas->Brush->Color=clRed;
StringGrid1->Canvas->FillRect(Rect);

for(int i=1;i <=5;i++) //第一行
DrawText(StringGrid1->Canvas->Handle,
StringGrid1->Cells[1][i].c_str(),-1,
(RECT*)&Rect,DT_SINGLELINE);
}
bob008 2008-09-21
  • 打赏
  • 举报
回复
fillrect应该能满足你的要求...请放在DRAWTEXT前

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧