Richview section indent

Source: Internet
Author: User
段落缩进在输入文字的过程中,如果按下回车键,新成生的段落会与当前段落对齐,下面例子只处理了回车,如果要实现自动换行时也达到同样效果,可以在其文字录入事情中作相同处理!实现过程主要是通得到当前光标所在段落(行)前面的空格数,然后在新段落头中插入同相的数目的空格function GetLeadingSpacesCount(rve: TCustomRichViewEdit): Integer; 
var StartItemNo, ItemNo, i: Integer; 
    s: String; 
begin 
  rve := rve.TopLevelEditor; 
  ItemNo := rve.CurItemNo; 
  while not rve.IsParaStart(ItemNo) do 
    dec(ItemNo); 
  Result := 0; 
  StartItemNo := ItemNo; 
  while ItemNo
    if (ItemNo>StartItemNo) and rve.IsParaStart(ItemNo) then 
      exit; //如果在段落头则不处理
    if rve.GetItemStyle(ItemNo)<0 then //如果不是文字也不处理
      exit; 
    s := rve.GetItemText(ItemNo); 
    for i := 1 to Length(s) do 
      if s[i]=‘ ‘ then 
        inc(Result) //计算空格数
      else 
        exit; 
    inc(ItemNo); 
  end; 
end; //通过空格数返回字符个数,空格也是字符function GetSpaces(Count: Integer): String; 
var i: Integer; 
begin 
  SetLength(Result, Count); 
  for i := 1 to Count do 
    Result[i] := ‘ ‘; 
end; 最后在KeyDown下面实现 if Key=VK_RETURN then begin 
    RichViewEdit1.InsertText(#13+GetSpaces(GetLeadingSpacesCount(RichViewEdit1))); 
    Key := 0; 
  end; 

RichView段落缩进

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.