1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
procedure TForm1.mnuDessinAllAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
procedure DrawChecked();
var
Glyph: TBitmap;
OldBrushColor: TColor;
GlyphRect: TRect;
begin
Glyph := TBitmap.Create;
try
Glyph.Transparent := True;
Glyph.Handle := LoadBitmap(0, PChar(OBM_CHECK));
OldBrushColor := ACanvas.Font.Color;
try
ACanvas.Font.Color := clRed; // Oui la couleur de la case à cocher est modifié par Font ou Pen Color ... étrange mais bon ça fonctionne
GlyphRect.Left := ARect.Left + 1;
GlyphRect.Top := ARect.Top + 1;
GlyphRect.Right := GlyphRect.Left + 16;
GlyphRect.Bottom := GlyphRect.Top + 16;
ACanvas.Draw(
GlyphRect.Left + (GlyphRect.Right - GlyphRect.Left - Glyph.Width) div 2 + 1,
GlyphRect.Top + (GlyphRect.Bottom - GlyphRect.Top - Glyph.Height) div 2 + 1,
Glyph);
finally
ACanvas.Font.Color := OldBrushColor;
end;
finally
Glyph.Free();
end;
end;
const
PEN_COLORS: array[Boolean] of TColor = (clBlack, clYellow);
BRUSH_COLORS: array[Boolean] of TColor = (clLime, clAqua);
var
MenuRect: TRect;
DrawStyle: Longint;
Text: string;
begin
ACanvas.Font.Color := PEN_COLORS[TMenuItem(Sender).Checked];
ACanvas.Pen.Color := PEN_COLORS[TMenuItem(Sender).Checked];
ACanvas.Brush.Color := BRUSH_COLORS[TMenuItem(Sender).Checked];
if odSelected in State then
ACanvas.Rectangle(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom)
else
ACanvas.FillRect(ARect);
if TMenuItem(Sender).Checked then
DrawChecked();
ARect.Left := ARect.Left + 1 + 16*2 + 2;
DrawStyle := DT_EXPANDTABS or DT_SINGLELINE or DT_LEFT;
Text := TMenuItem(Sender).Caption;
ARect.Top := ARect.Top + 2;
DrawText(ACanvas.Handle, Text, Length(Text), ARect, DrawStyle);
end;
procedure TForm1.mnuDessinAllMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
begin
Width := Width + 16;
end; |
Partager