最近写了个串口调试工具软件,虽然网上很多这类软件,但是自己写可以随时修改,比较方便,所以随手写了下面这个软件:

关于TRichEdit字体颜色控制

在考虑显示上下数据的控件的时候试了好几个控件,但是都不好用,后来选了TRichEdit控件,但是TRihEdit字体颜色显示的时候也走了些弯路,有时候该显示红色的变了黑色,修改后,到目前为止没有出现颜色错误或不改的状态。具体代码如下:

procedure TMainFrm.AddMemo(Buf: Pointer; nDataLen: Integer);
var
    Str: String;
    Str1: String;
    iTotal: Integer;
    iTotal1: Integer;
begin

    // 自动清空
    if cbxClear.Checked then
    begin
        if reInfo.Lines.Count >= FRow then reInfo.Clear;
    end;

    Str1 := '';

    // 显示日期时间
    if cbxDate.Checked then
    begin
        Str1 := '[' + FormatDatetime('YYYY-MM-DD hh:nn:ss.zzz', now) + ']';
    end;

    Str1 := Str1 + '[Receive]';

   // 显示Hex或ASCII

   if cbxShowHex.Checked then
       Str := GetStr(Buf, nDataLen)
    else
       Str := ASCIIToStr(Buf, nDataLen);

    Str1 := Str1 + ' ' + Str;

    iTotal := Length(reInfo.Text);
    iTotal1 := Length(Str1);

    reInfo.SelStart := iTotal + 1;
    reInfo.SelLength := iTotal1;
    reInfo.SelAttributes.Color := clBlue;
    reInfo.Lines.Add(Str1);

    FRecv := FRecv + 1;
    FRecvByte := FRecvByte + nDataLen;

    edtRecv.Text := IntToStr(FRecv);
    edtRecvByte.Text := IntToStr(FRecvByte);

    // 显示定位到最后一行   

    ShowLastItem;
end;
 

相关文章:

  • 2021-06-26
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-04
  • 2021-05-27
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
相关资源
相似解决方案