線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3384
推到 Plurk!
推到 Facebook!

RichEdit分行顏色的問題~

答題得分者是:jow
踏雪冬思
一般會員


發表:6
回覆:2
積分:1
註冊:2007-10-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-10-18 01:29:40 IP:58.46.xxx.xxx 訂閱
發送到RichEdit的顏色并不如我自己所定義的色彩,見附圖, 我寫的代碼如下,請高手幫助檢查,謝謝。

procedure TForm1.BitBtn5Click(Sender: TObject); //發送memo1中的文字到RichEdit,設顏色為紅
var
b:integer;
begin
b:=Length(RichEdit1.text);
With RichEdit1 do
begin
Lines.Add(Memo1.Lines.Text);
SelStart:=b-Length(Memo1.Text);
SelLength:=Length(Memo1.Text);
SelAttributes.Color:=clred;
end;
end;
====================
procedure TForm1.BitBtn6Click(Sender: TObject); //發送memo2中的文字到RichEdit,設顏色為藍色
var
i:integer;
begin
i:=Length(RichEdit1.text);
With RichEdit1 do
begin
Lines.Add(Memo2.text);
SelStart:=i-Length(Memo2.Text);
SelLength:=Length(Memo2.Text);
SelAttributes.Color:=clblue;
end;
end;

http://www.lsjtsg.com/yy/wt/11.png
附加檔案:47164684a8228_11.PNG
編輯記錄
踏雪冬思 重新編輯於 2007-10-18 01:33:03, 註解 無‧
踏雪冬思 重新編輯於 2007-10-18 01:34:34, 註解 無‧
踏雪冬思 重新編輯於 2007-10-18 13:11:24, 註解 無‧
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-10-18 15:54:23 IP:210.66.xxx.xxx 訂閱

[code delphi]
unit fMain;

interface


uses
Classes, Graphics, Controls, Forms, StdCtrls, ComCtrls;


type
TForm1 = class(TForm)
Memo1: TMemo;
RichEdit1: TRichEdit;
Button1: TButton;
Memo2: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
procedure AddToRichEdit(S: string; FontColor: TColor);
end;


var
Form1: TForm1;


implementation


uses SysUtils;


{$R *.dfm}


procedure TForm1.AddToRichEdit(S: string; FontColor: TColor);
var
P: Integer;
begin
P := Length(RichEdit1.Text);//Keep Append Position
with RichEdit1 do
begin
Lines.Add(Trim(S));
SelStart := P;
SelLength := Length(Trim(S));
SelAttributes.Color := FontColor;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
AddToRichEdit(Memo1.Lines.Text, clRed);
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
AddToRichEdit(Memo2.Lines.Text, clBlue);
end;


end.
[/code]
系統時間:2024-04-29 6:07:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!