AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein GUI-Design mit VCL / FireMonkey / Common Controls Delphi Komponente TMemoEx - ein TMemo mit Zeilennummern
Thema durchsuchen
Ansicht
Themen-Optionen

Komponente TMemoEx - ein TMemo mit Zeilennummern

Ein Thema von turboPASCAL · begonnen am 30. Okt 2005 · letzter Beitrag vom 3. Nov 2005
 
Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#1

Komponente TMemoEx - ein TMemo mit Zeilennummern

  Alt 30. Okt 2005, 15:30
Irgend wann mal braucht man Zeilennummern in einem Memo. Klar, es gibt SynEdit ist aber manchmal ein bissel gross... Warum nicht mal als kleine Komponente ?

Ja ist doch einfach..., das dachte ich mir heute früh und tippte darauf los. Gar nicht so einfach denke ich jetzt.

Soweit funktioniert es jetzt, jedoch gibt es noch ein Problem. Wenn in einer neuen Zeile ein Zeichen eingeg. wird springt der Zähler auf eine neue Zeile.


Wer kann helfen (Bitte nicht nur "Ich" sagen )?


Delphi-Quellcode:
unit MemoEx;

{...}

implementation

{...}

function CountVisibleLines(const Memo: TMemo): Integer;
var
  OldFont: HFont;
  DC: THandle;
  TextMetric: TTextMetric;
begin
  Result := 0;

  DC := GetDC(Memo.Handle);
  try
    OldFont := SelectObject(DC, Memo.Font.Handle);
    try
      GetTextMetrics(DC, TextMetric);
      Result := (Memo.ClientRect.Bottom - Memo.ClientRect.Top) div
        (TextMetric.tmHeight + TextMetric.tmExternalLeading);
    finally
      SelectObject(DC, OldFont);
    end;
  finally
    ReleaseDC(Memo.Handle, DC);
  end;
end;

procedure CalcRect(var R: TRect; aScrollBars: TScrollStyle);
begin
  if aScrollBars = ssBoth then
  begin
    R.Right := R.Right - GetSystemMetrics(SM_CYVSCROLL);
    R.Bottom := R.Bottom - GetSystemMetrics(SM_CYHSCROLL);
  end else
  if aScrollBars = ssHorizontal then
  begin
    R.Bottom := R.Bottom - GetSystemMetrics(SM_CYHSCROLL);
  end else
  if aScrollBars = ssVertical then
    R.Right := R.Right - GetSystemMetrics(SM_CYVSCROLL);
end;

procedure TMemoEx.WMPaint(var Msg: TWMPaint);
var
  canv: Tcanvas;
  r: trect;
  i, h, y: Integer;
  FirstVisibleLine,
  VisibleLines: Integer;
begin
  inherited;

  canv := tcanvas.Create;
  canv.Handle := GetWindowDC(Handle);

  r := ClientRect;
  if self.BorderStyle = bsSingle then
  begin
    r.Top := +GetSystemmetrics(SM_CXEDGE);
    r.Left := +GetSystemmetrics(SM_CXEDGE);
    r.Bottom := r.Bottom + GetSystemmetrics(SM_CXEDGE);
  end;

  FirstVisibleLine := SendMessage(self.Handle, EM_GETFIRSTVISIBLELINE, 0, 0);
  VisibleLines := CountVisibleLines(Self);

  with canv do
  begin
    r.Right := FGutterSize;
    brush.Color := clbtnface;

    if FGutterType = gtLine then
    begin
      brush.Color := clWindow;
      pen.Color := cl3DDkShadow;
      canv.MoveTo(r.Right - 2, r.Top);
      canv.LineTo(r.Right - 2, r.Bottom);
    end else
    begin
      FillRect(r);
      Frame3D(canv, r, clBtnHighlight, clBtnShadow, 1);
    end;

    Font := self.Font;
    Font.Color := clBtnText;

    if self.Lines.Count < VisibleLines then h := self.Lines.Count
    else h := FirstVisibleLine + (VisibleLines - 1);

    y := 0;
    for i := FirstVisibleLine to h do
    begin
      TextOut(r.Left + 8, r.Top + (y * textheight('X')),
        format('%4.4d', [i + 1]));
      inc(y);
    end;
  end;

  canv.Free;
end;

{...}
Angehängte Grafiken
Dateityp: png image1_202.png (8,9 KB, 108x aufgerufen)
Angehängte Dateien
Dateityp: zip memoex_703.zip (1,8 KB, 65x aufgerufen)
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz