Einzelnen Beitrag anzeigen

Schorschi5566

Registriert seit: 6. Feb 2006
197 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#2

AW: ComboBox: Optik von csOwnerDrawFixed ähnlich wie csDropDownList

  Alt 5. Feb 2011, 16:41
Jetzt isses schon etwas besser aber ich bekomme das entsprechende TRect nicht völlig über die Komponente.

Hier ist mal ein bissel Code. Vielleicht fällt ja jemandem ein, wie man das hinkriegen könnte...

Delphi-Quellcode:
procedure TCheckComboBox.DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  sOut : String;
  Details: TThemedElementDetails;
  ARect : TRect;
begin
  SetLength(Selected, TComboBox(Control).Items.Count);
  with TComboBox(Self).Canvas do
  begin
    FillRect(rect);

    ARect.Left := Rect.Left + 1;
    ARect.Right := Rect.Left + 13;
    ARect.Bottom := Rect.Bottom;
    ARect.Top := Rect.Top;

    if not (odComboBoxEdit in State) then
    begin
      if not (odSelected in State) and (Selected[Index]) then
        DrawFrameControl(Handle, ARect, DFC_BUTTON,
          DFCS_BUTTONCHECK or DFCS_CHECKED or DFCS_FLAT)
      else if (odFocused in State) and (Selected[Index]) then
        DrawFrameControl(Handle, ARect, DFC_BUTTON,
          DFCS_BUTTONCHECK or DFCS_CHECKED or DFCS_FLAT)
      else if (Selected[Index]) then
        DrawFrameControl(Handle, ARect, DFC_BUTTON,
          DFCS_BUTTONCHECK or DFCS_CHECKED or DFCS_FLAT)
      else if not (Selected[Index]) then
        DrawFrameControl(Handle, ARect, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_FLAT);

      TextOut(ARect.Left + 15, ARect.Top, TComboBox(Control).Items[Index]);
    end

// um den folgenden Part geht es...


    else // Text bei geschlossener ComboBox ohne Checkmarks
    begin
      sOut := '';
      for i := 0 to Items.Count - 1 do
      begin
        if Selected[i] then
          sOut := sOut + ItemsShort[i] + Separator;
      end;
      sOut := StrTrimRight(sOut, Char(Separator));
      ARect := Self.ClientRect;
      ARect.Top := ARect.Top - 1;
      ARect.Bottom := ARect.Bottom + 1;
      ARect.Left := ARect.Left - 1;
      ARect.Right := ARect.Right;
      Details := ThemeServices.GetElementDetails(tbPushButtonNormal);
      ARect := ThemeServices.ContentRect(Handle, Details, ARect);
      ThemeServices.DrawEdge(Handle, Details, ARect, EDGE_RAISED, BF_RECT);
      ThemeServices.DrawElement(Handle, Details, ARect);
      ARect.Left := ARect.Left + 4;
      ARect.Top := ARect.Top + 2;
      ThemeServices.DrawText(Handle, Details, sOut, ARect, BF_FLAT, BF_FLAT);
    end;
  end;
end;
Habe schon Bevels und dergleichen deaktiviert aber ich komme nicht in die linke obere Ecke...(siehe Screenshot)


Grüße,
Uwe
Miniaturansicht angehängter Grafiken
screenshot2.jpg  
Uwe
"Real programmers can write assembly code in any language." - Larry Wall
Delphi programming rocks
  Mit Zitat antworten Zitat