有关RichEdit的操作:如何知道行所处的位置?如何使一行有背景色?

落伍的小农 2005-03-24 02:11:39
在RICHEEDIT如何实现:
1.获得一行的位置,也就是这行在RICHEEDIT中的Top,Bottom的值?
2.整行出现红色的背景色,不是字体的背景色而是整行的背景色。
3.在每行的开头标识出此行在RICHEEDIT中的行号,当然这个标识是不能用退格键消去的,就象是画上去的不能更改。当然也可以在RICHEEDIT外面用另外的组件实现,只要它能对应标出RICHEEDIT中的行号。

...全文
308 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
落伍的小农 2005-04-20
  • 打赏
  • 举报
回复
hellolongbin(一个人) 能给我具体的帖子地址吗?
落伍的小农 2005-04-12
  • 打赏
  • 举报
回复
hellolongbin(一个人) 能给我具体的帖子地址吗?
落伍的小农 2005-04-12
  • 打赏
  • 举报
回复
西门吹雪的方法以前我就用过,我要的不是这个效果!
是整行变色,其实我想做的就象DELPHI代码编写器那样!
Forgetying 2005-04-08
  • 打赏
  • 举报
回复
TO:XuDunYu(西门吹雪)
好像我试用时,不是每一行显示,而是每一个字符显示?
XuDunYu 2005-04-08
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, CustomizeDlg, ShellCtrls, ExtCtrls,richedit;

type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure SetRicheditLineColor(RichEdit:TRichEdit;FontColor,LineBackGroundColor :TColor;LineIndex:Integer);
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}



//函数必须引用 richEdit 单元;
procedure TForm1.SetRicheditLineColor(RichEdit:TRichEdit;FontColor,LineBackGroundColor :TColor;LineIndex:Integer);
var i:Integer;
c:integer;
backStart : integer;
Fmt :TCharFormat2;
begin
c:=0; //计数器归零
backStart := RichEdit.SelStart; //备份光标位置
for i:=0 to RichEdit.Lines.Count-1 do
begin
if i=lineIndex then
begin
RichEdit.SelStart := c; //寻找选择区域的起点位置
RichEdit.SelLength := length(richedit1.Lines.Strings[i]); //获得选择当前行的长度
Fmt.cbSize := SizeOf(Fmt);//这里放传递的结构大小,系统通过这个知道传递的是CharFormat还是CharFormat2
Fmt.dwMask := CFM_COLOR or CFM_BACKCOLOR;//告诉系统只有字体颜色和背景颜色两个字段的值有效
Fmt.crTextColor := FontColor;//设置字体颜色
Fmt.crBackColor := LineBackGroundColor;//设置字体背景色
RichEdit.Perform(EM_SETCHARFORMAT,SCF_SELECTION,integer(@Fmt));//发EM_SETCHARFORMAT消息给RichEdit,表示只有选择部分加背景颜色
RichEdit.SelLength := 0; //恢复选择
break; //中断
end;
c := c + length(RichEdit.Lines.Strings[i]) + 2; //+2表示#13#10,windows 系统是回车+换行 2个字符
end;
RichEdit.SelStart := backStart ; //恢复光标位置
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SetRicheditLineColor( richedit1,clRed,clBlue,1); //设置第2行的字体为红色,背静为蓝色
end;

end.
hellolongbin 2005-04-08
  • 打赏
  • 举报
回复
发贴之前搜了没有?类似的贴子都回答够了
落伍的小农 2005-04-08
  • 打赏
  • 举报
回复
再没人帮我,就把这帖子删了!
lscxp 2005-04-08
  • 打赏
  • 举报
回复
先顶,再收藏了
caiso 2005-03-25
  • 打赏
  • 举报
回复
顶一下
落伍的小农 2005-03-25
  • 打赏
  • 举报
回复
怎么就没人理我的帖子,高手都去哪了?
落伍的小农 2005-03-24
  • 打赏
  • 举报
回复
哎,怎么回答问题的人怎么少?

5,913

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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