RichView的幾個封裝函數(插入文本和圖片)

 //移動光標到最後

procedure RichViewMoveCaretToEnd(RichEdit: TRichViewEdit);
var
  ItemNo, Offs: Integer;
begin
  ItemNo := RichEdit.ItemCount-1;
  if ItemNo > 0 then
  begin
    Offs := RichEdit.GetOffsAfterItem(ItemNo);
    RichEdit.SetSelectionBounds(ItemNo, Offs, ItemNo, Offs);
  end;
end;

// 向RichView中增加文本(注意裏邊檢查了Style是否存在)

procedure RichViewAddText(RichEdit: TRichViewEdit; const S: string;
  FontInfo: TFontInfo);
const
  RV_FIND_PROP: TRVFontInfoProperties =
    [rvfiFontName, rvfiSize, rvfiBold, rvfiItalic,
    rvfiUnderline, rvfiStrikeout, rvfiColor];
var
  LStyleNo: Integer;
  LNewFontInfo: TFontInfo;
begin
  LStyleNo := RichEdit.Style.TextStyles.FindSuchStyle(0, FontInfo, RV_FIND_PROP);
  if LStyleNo < 0 then
  begin
    LNewFontInfo := RichEdit.Style.TextStyles.Add;
    LNewFontInfo.Assign(FontInfo);
    LNewFontInfo.Unicode := True;
    LStyleNo := RichEdit.Style.TextStyles.Count - 1;
  end;
  RichEdit.ApplyTextStyle(LStyleNo);
  RichEdit.InsertTextW(S);
end;

// 向RichView中增加文本

procedure RichViewAddText(RichEdit: TRichViewEdit;
  const S: string; const FontName: string; FontSize: Integer;
  FontColor: TColor; FontStyle: TFontStyles);
var
  LFontInfo: TFontInfo;
begin
  LFontInfo := TFontInfo.Create(nil);
  try
    LFontInfo.FontName := FontName;
    LFontInfo.Size := FontSize;
    LFontInfo.Color := FontColor;
    LFontInfo.Style := FontStyle;

    RichViewAddText(RichEdit, S, LFontInfo);
  finally
    LFontInfo.Free;
  end;
end;

// 向RichView中增加圖片

procedure RichViewAddPicture(RichEdit: TRichViewEdit; const TagStr: string;
  Stream: TMemoryStream; IsGif: Boolean);
var
  LGraphic: TGraphic;
begin
  if IsGif then
  begin
    LGraphic := TGIFImage.Create;
  end else
  begin
    LGraphic := TBitmap.Create;
  end;

  Stream.Position := 0;
  LGraphic.LoadFromStream(Stream);
  RichEdit.InsertPicture(TagStr, LGraphic, rvvaBaseline);
end;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章