Einzelnen Beitrag anzeigen

norwegen60

Registriert seit: 23. Dez 2007
Ort: Schwarzwald
504 Beiträge
 
Delphi 12 Athens
 
#1

Komponente wird nicht sauber gezeichnet

  Alt 3. Jan 2011, 21:39
Hallo zusammen,

ich arbeite seit Jahren mit der Komponente "TDBLookupComboPlus". Jetzt bin ich am Umstellen von Delphi 7 auf XE und habe die Komponente auch soweit, dass sie mit Delphi XE arbeitet. Beim Einsatz von TMS-Controls, z.B. ADVPageControl oder ADVPanel habe ich jetzt aber das Problem, dass die Lookup-Komponente nicht mehr sauber gezeichnet wird. Sobald ich in der IDE ein Fenster darüber ziehe, bleiben in dem Combo-Feld die Reste des darüber gezogenen Fensters stehen. Beim ausgeführten Programm funktioniert es etwas besser. Da bleiben nur am Rand kleine Reste eines darüber gezogenen Fensters hängen. Richtig schön aussehen tut es aber auch da nicht.
Ich habe mich noch nie mit dem Erstellen von Komponenten befasst und möchte es eigentlich auch nicht. Die Suche nach misslungenen Paint-Versuchen hat mir auch nicht viel weiter geholfen. Ich stelle deshalb mal das Original Paint-Ereignis hier rein. Vielleicht sieht ja einer woran es liegen könnte.

Delphi-Quellcode:
procedure TDBLookupComboPlus.WMPaint(var Message: TWMPaint);
var
{$IFNDEF Win32}
  S: array[0..255] of Char;
{$ELSE}
  S : Variant; //String;
{$ENDIF}
  PS: TPaintStruct;
  ARect: TRect;
  TextLeft, TextTop: Integer;
  Focused: Boolean;
  DC: HDC;
  Metrics : TTextMetric; {new 1/23/96}
begin
  if (Editable or (fstyle = csIncSearch)) and (Text <> '')
{$IFDEF Win32}
  and not (csPaintCopy in ControlState)
{$ENDIF}
     then
  begin
    inherited;
    Exit;
  end;
  { if not editable with focus, need to do drawing to show proper focus }
  if FCanvas = nil then
  begin
    FCanvas := TControlCanvas.Create;
    FCanvas.Control := Self;
  end;
  DC := Message.DC;
  if DC = 0 then DC := BeginPaint(Handle, PS);
  FCanvas.Handle := DC;
  try
    Focused := (GetFocus = Handle) {$IFDEF Win32}and not(csPaintCopy in ControlState){$ENDIF};
    FCanvas.Font := Font;
    with FCanvas do
    begin
      ARect := ClientRect;
      if (BorderStyle = bsSingle) then
      begin
        Brush.Color := clWindowFrame;
 {$IFNDEF Win32}
        FrameRect(ARect); { draw the border }
 {$ENDIF}
        InflateRect(ARect, -1, -1);
      end;
      if not (Editable or (fstyle = csIncSearch)) or
             ((Text = '') and (fstyle = csIncSearch))
{$IFDEF Win32}
             or (csPaintCopy in ControlState)
{$ENDIF}
             then
      begin
        Brush.Style := bsSolid; {fill the recttangle inside the boarder with color}
        Brush.Color := Color;
        FillRect (ARect);
        if (BorderStyle = bsSingle) then
          TextTop := FTopTextMargin
        else {bsNone}
          TextTop := FTopTextMargin;
        if ShowSpeedButton then
          ARect.Right := FBtnControl.Left - 1
        else
          ARect.Right := ClientWidth - 2; {new 1/21/96 Deven report added '- 2'}
{$IFNDEF Win32}
        StrPCopy (S, Text);
{$ENDIF}
        TextLeft := FLeftTextMargin;
        if Focused then {draw the focus rectangle}
        begin
          Brush.Color := clHighlight;
          Font.Color := clHighlightText;
          ARect.Top := ARect.Top + FTopTextMargin;
{}        GetTextMetrics(FCanvas.Handle, Metrics); {new 1/23/96}
          ARect.Bottom := ARect.Top + Metrics.tmHeight;
        end;
{$IFDEF Win32}
{CtlGrid}      if (csPaintCopy in ControlState) and (FFieldLink.Field <> nil) and
{CtlGrid}          (LookupSource <> nil) then
{CtlGrid}      begin
{CtlGrid}        If (LookupField = LookupDisplay) or (FFieldLink.Field.DisplayText = '') then {don't do the lookup if not necessary}
{CtlGrid}          S := FFieldLink.Field.DisplayText
{CtlGrid}        else
{CtlGrid}          S := LookupSource.DataSet.Lookup(LookupField, FFieldLink.Field.DisplayText,
{CtlGrid}            LookupDisplay);
{CtlGrid}        If VarIsNull(S) then
{CtlGrid}          S := ''
{CtlGrid}        else if not VarIsEmpty(S) then S := '';
{CtlGrid}        ExtTextOut(FCanvas.Handle, TextLeft, TextTop, ETO_OPAQUE or ETO_CLIPPED, @ARect,
{CtlGrid}        PChar(String(S)), Length(String(S)), nil);
{CtlGrid}      end
{CtlGrid}      else
        ExtTextOut(FCanvas.Handle, TextLeft, TextTop, ETO_OPAQUE or ETO_CLIPPED, @ARect,
          PChar(Text), Length(Text), nil);
{$ELSE}
        ExtTextOut(FCanvas.Handle, TextLeft, TextTop, ETO_OPAQUE or ETO_CLIPPED, @ARect,
          S, StrLen(S), nil);
{$ENDIF}
        If assigned(FBtnControl) then FBtnControl.refresh;
        if Focused then
          DrawFocusRect (ARect);
      end;
    end;
  finally
    FCanvas.Handle := 0;
    if Message.DC = 0 then EndPaint(Handle, PS);
  end;
end;
Vielen Dank für eure Hilfe
Gerd
  Mit Zitat antworten Zitat