AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Artefakte beim Zeichnen auf Edit Canvas

Ein Thema von Roaster · begonnen am 14. Okt 2009 · letzter Beitrag vom 15. Okt 2009
 
Roaster

Registriert seit: 21. Jul 2004
Ort: bei mir zu Hause
107 Beiträge
 
#1

Artefakte beim Zeichnen auf Edit Canvas

  Alt 14. Okt 2009, 15:24
Hi,

ich habe JvEdit so abgeändert, dass ich in einer Art Präfix vor dem eigentlichen Edit Text eine Grafik darstellen kann, siehe Bild.
Das Problem, dass ich habe ist, dass oberhalb und auf der linken Seite der Grafik, oder genauer gesagt Hintergrund, manchmal Reste von anderen Fenstern stehen bleiben.
Ich habe dies mal im Bild mit gelber Farbe markiert.

Den Code, den ich verwende ist:

Delphi-Quellcode:
procedure TJvEdit.WndProc(var Msg: TMessage);
begin
  case Msg.Msg of
    CN_CTLCOLORSTATIC,
    CN_CTLCOLOREDIT:
      if Images <> nil then
        ExcludeClipRect(Msg.WParam, 1, 1, Images.Width + FImageMarginRight + 2, Images.Height);
  end;

  inherited WndProc(Msg);

  case Msg.Msg of
    WM_SIZE, WM_SETFONT, WM_FONTCHANGE, WM_WINDOWPOSCHANGED,
    CM_FONTCHANGED, CM_BORDERCHANGED, CM_CTL3DCHANGED:
      if not (csLoading in ComponentState) then
        UpdateEditMargins;
  end;
end;

procedure TJvEdit.WMPaint(var Msg: TWMPaint);
var
  MyDC: Boolean;
  ps: TPaintStruct;
  NewPen, OldPen: HPEN;
  Canvas: TCanvas;
begin
  if Images <> nil then
  begin
    if UpdateEditMargins then
      Exit; // UpdateEditMargins called Invalidate()

    MyDC := Msg.DC = 0;
    if MyDC then
      Msg.DC := BeginPaint(Handle, ps);

    inherited;

    // Draw gradient filled rectangle
    Canvas := TCanvas.Create;
    Canvas.Handle := Msg.DC;
    GradientFillCanvas(Canvas, FPrefixColorFrom, FPrefixColorTo,
      Rect(0, 0, Images.Width + FImageMarginRight + 2, Images.Height + 1),
      FPrefixColorDirection);

    // Draw bitmap
    if ImageIndex <> -1 then
      case FImageAlignment of
        taLeftJustify : ImageList_Draw(Images.Handle, ImageIndex,
                          Msg.DC, 0, 1, ILD_NORMAL);
        taRightJustify: ImageList_Draw(Images.Handle, ImageIndex,
                          Msg.DC, FImageMarginRight, 1, ILD_NORMAL);
        taCenter: ImageList_Draw(Images.Handle, ImageIndex, Msg.DC,
                          (FImageMarginRight div 2), 1, ILD_NORMAL);
      end;

    // Show separator line
    if FShowLine then
    begin
      NewPen := CreatePen(PS_SOLID, 1, ColorToRGB(FLineColor));
      OldPen := SelectObject(Msg.DC, NewPen);

      MoveToEx(Msg.DC, Images.Width + FImageMarginRight + 1, 0, Nil );
      LineTo(Msg.DC, Images.Width + FImageMarginRight + 1, Height);

      SelectObject(Msg.DC, OldPen);
      DeleteObject(NewPen);
    end;

    if MyDC then
      EndPaint(Handle, ps);

    Canvas.Free;
  end
  else
    inherited;
end;

function TJvEdit.UpdateEditMargins: Boolean;
var
  Margins: Integer;
  LeftMargin: Integer;
begin
  Result := False;
  if HandleAllocated then
  begin
    LeftMargin := 0;
    if Images <> nil then
      LeftMargin := Images.Width + FImageMarginRight + 2;

    Margins := SendMessage(Handle, EM_GETMARGINS, 0, 0);
    if (Margins and $FFFF) <> LeftMargin then
    begin
      SendMessage(Handle, EM_SETMARGINS, EC_LEFTMARGIN, MakeLong(LeftMargin, 0));
      Invalidate;
      Result := True;
    end;
  end;
end;
Im fehlenden Code sind hauptsächlich noch die Setter und Getter für die Properties drin. Das Zeichnen findet im o.g. Coding statt.
Wie gesagt es funktioniert alles, bis auf die Überbleibsel rund um die Grafik/Hintergund herum.

Weiß jemand Rat? Danke!

Credits: Die Codebasis stammt übrigens von Andreas Hausladen - Danke auf diesem Weg nochmals!
Angehängte Grafiken
Dateityp: png artefakte_jvedit_179.png (2,2 KB, 50x aufgerufen)
cu, Michael

Windows 7, WinXP Pro, Vista, WinXP Home, Win98 SE
D4 C/S, D7 Enterprise, Turbo Delphi Pro, Delphi 2009
  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 18:36 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz