C++Builder 怎么把RichEdit追加的字符串 指定某个颜色?
C++Builder 怎么把RichEdit追加的字符串 指定某个颜色?
(不影响RichEdit原有字符的颜色?)
[解决办法]
哦,泄特,乱码了,重发。
RichEdit1->Lines->Add("默认颜色的字符串");
RichEdit1->SelAttributes->Color = clRed;
RichEdit1->Lines->Add("红颜色的字符串");
RichEdit1->SelAttributes->Color = clBlue;
RichEdit1->Lines->Add("蓝颜色的字符串");
RichEdit1->SelAttributes->Color = clBlack;
RichEdit1->Lines->Add("黑颜色的字符串");
// 添加输出信息到 文本框
bool TfrmMain::RichEditAdd(WideString str, TColor clr)
{
// 获取长度
int nLength = this->RichEdit->Lines->Text.Length()
-this->RichEdit->Lines->Count;
// 输出格式
str = L"[" + DateTimeToStr(Now()) + L"]: " + str; // 获取当前时间
// 添加文本,并设置颜色
this->RichEdit->Lines->Add(str);
this->RichEdit->SelStart = nLength;
this->RichEdit->SelLength = str.Length();
this->RichEdit->SelAttributes->Color = clr;
this->RichEdit->SelLength = 0;
return true;
}