Marge dans un RichEdit ?

Résolu
arnaud_tournier Messages postés 34 Date d'inscription jeudi 16 septembre 2004 Statut Membre Dernière intervention 25 mars 2007 - 20 nov. 2004 à 13:51
ni69 Messages postés 1418 Date d'inscription samedi 12 juin 2004 Statut Membre Dernière intervention 5 juillet 2010 - 20 nov. 2004 à 22:03
Hello everybody,

J aurais aimer savoir si quelqu un savait comment mettre la marge d 'un richedit d'un autre couleur que le richEdit et comment écrire dans cette marge. En fait, j aimerais pouvoir mettre les numéros de lignes dans le RichEdit comme la plupart des éditeurs de texte...

Merci d'avance....

Arnaud

2 réponses

arnaud_tournier Messages postés 34 Date d'inscription jeudi 16 septembre 2004 Statut Membre Dernière intervention 25 mars 2007
20 nov. 2004 à 21:51
Merci pour votre aide les gars mais j'y suis arrivé, je vous donne le code source pour que ca puiss servir à quelqu un d autre....

unit UNewRichEdit;

interface

uses
Windows, Messages, RichEdit;

type
TNewRichEdit = class(TCustomRichEdit)
private
{ Déclarations privées }
FOnScroll: TNotifyEvent;
MARGINWIDTH : integer;
protected
procedure WndProc(var Msg: TMessage); override;
public
{ Déclarations publiques }
procedure CreateWnd(); override;
procedure drawMarge();
published
property OnScroll: TNotifyEvent read FOnScroll write FOnScroll;
end;

implementation

{ TNewRichEdit }

procedure TNewRichEdit.CreateWnd;
begin
inherited;
SendMessage(Self.Handle, EM_SETWORDBREAKPROC, 0, LPARAM(@EditWordBreak));
LongRec(Margins).Lo := 30;
LongRec(Margins).Hi := 30;
MARGINWIDTH := TFrmChild(Parent).Canvas.TextWidth('0000') + 6;
SendMessage(Self.Handle, EM_SETMARGINS, EC_LEFTMARGIN,MARGINWIDTH);
end;

procedure TNewRichEdit.drawMarge;
var Rect : TRect;
sTmp : String;
Canvas : TCanvas;
iStart : integer;
iEnd : integer;
iHeightOneChar : integer;
iLineVisible : integer;
info: TScrollInfo;
iDec : integer;
begin
iHeightOneChar := TFrmChild(Parent).Canvas.TextHeight('0');
FillChar(info, SizeOf(info), 0);
with info do
begin
cbsize := SizeOf(info);
fmask := SIF_ALL;
GetScrollInfo(Handle, SB_VERT, info);
end;
iDec := 0;
iStart := Perform(EM_GETFIRSTVISIBLELINE,0,0) + 1;

Canvas := TCanvas.Create;
Canvas.Handle := GetWindowDC(Self.Handle);
Canvas.Font.Color := clWhite;
Canvas.Font.Name := Self.Font.Name;
Canvas.Font.Size := Self.Font.Size;
Canvas.Brush.Color := clGray;

iEnd := Perform(EM_GETLINECOUNT,0,0) + 1;
iLineVisible := 0;
sTmp := '';

while ((iLineVisible * iHeightOneChar < ClientHeight)) do
begin
if (iLineVisible >= iEnd - 1) then
begin
sTmp := sTmp + ' ' + #13#10;
end
else
begin
sTmp := sTmp + ' ' + IntToStr(iStart + iLineVisible) + #13#10;
end;
inc(iLineVisible);
end;
Rect.Top := 0;
Rect.Left := MARGINWIDTH - 3;
Rect.Right := MARGINWIDTH;
Rect.Bottom := ClientHeight;
Windows.FillRect(Canvas.Handle, Rect, GetStockObject(GRAY_BRUSH));
Rect.Left := 0;
Rect.Top := - iDec;
Rect.Right := MARGINWIDTH - 3;
Windows.DrawText(Canvas.Handle, PChar(sTmp), length(sTmp), Rect, DT_RIGHT);
Canvas.Font.Color := clBlack;
ReleaseDC(Self.Handle, Canvas.Handle);
FreeAndNil(Canvas);
end;

procedure TNewRichEdit.WndProc(var Msg: TMessage);
begin
inherited;
if Msg.Msg = WM_VSCROLL then
begin
drawMarge;
end
else if Msg.Msg = WM_PAINT then
begin
drawMarge;
end;
end;

end.

Arnaud
3
ni69 Messages postés 1418 Date d'inscription samedi 12 juin 2004 Statut Membre Dernière intervention 5 juillet 2010 12
20 nov. 2004 à 22:03
ok ;)

@+
Bonne Prog'
Nico
0
Rejoignez-nous