Entwickler-Ecke

Grafische Benutzeroberflächen (VCL & FireMonkey) - Pen-Styles in ComboBox


cerebrum - Di 01.10.02 12:33
Titel: Pen-Styles in ComboBox
Hallo!
Wie kann ich die Pen-Styles des Canvas-Objekts in eine ComboBox einfügen, so dass der Benutzer diese auswählen kann?


LCS - Di 01.10.02 13:09

Hi
nimm eine ComboBox und füge als Items die zahlen 0 bis 4 ein. Style der ComboBox muss csOwnerDrawFixed sein.
Dann erstellst du eine Ereignisroutine für OnDrawItem:

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TfrmMain.cbxDrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
   with (Control as TcomboBox).Canvas do begin
       case Index of
           0: Pen.Style := psSolid;
           1: Pen.Style := psDash;
           2: Pen.Style := psDot;
           3: Pen.Style := psDashDot;
           4: Pen.Style := psDashDotDot;
       end;
       if  odSelected in State then
           Pen.Color := clHighLightText
       else
           Pen.Color := clWindowText;
       FillRect(rect);
       MoveTo(Rect.Left,Rect.Bottom - ((Rect.Bottom - Rect.Top) div 2));
       LineTo(Rect.Right, Rect.Bottom - ((Rect.Bottom - Rect.Top) div 2));
   end;
end;


Gruss Lothar


cerebrum - Di 01.10.02 14:25

Danke, klappt einwandfrei!! :dance2: