Как я могу использовать другой цвет текста для отключенных элементов меню, которые рисуются владельцем?

У меня есть этот код для раскрашивания MainMenu в Delphi. Он хорошо работает с событиями OnDrawItem, но мне нужно еще что-то, и я не знаю, как это сделать. Я бы хотел, чтобы шрифт пункта MainMenu, если пункт стал отключенным (enabled = False), был clSilver…

procedure TForm1.Nouveau1DrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
begin
  // déterminer la couleur et la font de la item séléctionnée    
  if Selected  Then
  begin
    // changer la couleur du canevas on lui attribuer la couleur de
    // séléction du style XP
    ACanvas.Brush.Color := $0084E3FF;
    // créer le rectangle qui sera afficher
    MRect.Left := Arect.Left+28;
    MRect.Top := ARect.Top+1;
    MRect.Right := ARect.Right-1;
    MRect.Bottom := ARect.Bottom-1;
    // redéssiner la Item
    ACanvas.FillRect(MRect);

    // créer la bordure du réctangle séléctionné
    ACanvas.Brush.Color := clMaroon;    

    // affichage du text

    // passer en mode affichage trensparent
    setBkMode(ACanvas.Handle, Transparent);
    // définition de la font
    ACanvas.Font.Style := [fsBold];
    ACanvas.Font.Color := $000000C1;

    // affichage du text
    DrawMenuText(30, ACanvas, ARect, (sender as TMenuItem).Hint);

    // créer la Frame qui presente la bordure de la séléction
    ACanvas.FrameRect(MRect);
  end else

  // déterminer la couleur et la font de la item
  begin
    // réctangle du glyph

    // 1)- réctangle principal ou sera affiché le text (Captions) des (items)
    ACanvas.Brush.Color := $0060D3F0;
    ACanvas.FillRect(ARect);

    begin
      // Réctangle qui représente le canevas du menu (arričre plan)
      ACanvas.Brush.Color := $0060D3F0;
      PRect.Left := ARect.Left + 1;
      PRect.Top := ARect.Top + 1;
      PRect.Right := PRect.Left + 25;
      PRect.Bottom := ARect.Bottom - 1;

      ACanvas.FillRect(PRect);

      // réctangle qui est comme étant l'arričre du text Caption
      ACanvas.Brush.Color := $00009FCE; // $0060D3F0;

      GRect.Left := ARect.Left + 27;
      GRect.Top := ARect.Top;
      GRect.Right := ARect.Right;
      GRect.Bottom := ARect.Bottom;

      ACanvas.FillRect(GRect);

      SetBKMode(ACanvas.Handle, Transparent);

      ACanvas.Font.Color := ClNavy;

      if not (Sender as TMenuItem).checked then
        DrawMenuText(30, ACanvas, GRect, (Sender as TMenuItem).Hint)
      else
      begin
        ACanvas.Brush.Color := $000000C1;
        MRect.Left := ARect.Left + 5;
        MRect.Top := ARect.Top + 5;
        MRect.Right := MRect.Left + 20;
        MRect.Bottom := ARect.Bottom - 5;

        ACanvas.FillRect(MRect);

        ACanvas.Brush.Color := clMaroon;

        ACanvas.FrameRect(MRect);

        SetBKMode(ACanvas.Handle, Transparent);

        // dessin du radioButton
        begin
          // 1)---------
          ACanvas.Pen.Color := $00CCF3FF;

          ACanvas.MoveTo(MRect.Left + 3, MRect.Top + 5);
          ACanvas.LineTo(MRect.Left + 5, MRect.Bottom - 3);

          // 2)---------
          ACanvas.MoveTo(MRect.Left + 3, MRect.Top + 5);
          ACanvas.LineTo(MRect.Left + 7, MRect.Bottom - 3);

          // 3)---------
          ACanvas.MoveTo(MRect.Left + 4, MRect.Bottom - 3);
          ACanvas.LineTo(MRect.Right -3, MRect.Top+2);

          // 4)---------
          ACanvas.MoveTo(MRect.Left + 6, MRect.Bottom - 3);
          ACanvas.LineTo(MRect.Right -3, MRect.Top +2);

          // 5)---------
        end;
        DrawMenuText(30, ACanvas, GRect, (Sender as TMenuItem).Hint)
      end;
    end;
  end;
end;

person Andras Kelemen    schedule 29.11.2011    source источник


Ответы (1)


Это должно быть довольно легко:

{ passer en mode affichage trensparent }
setBkMode(ACanvas.Handle, Transparent);
{ définition de la font }
ACanvas.Font.Style := [fsBold]  ;

if (Sender as TMenuItem).Enabled then
  ACanvas.Font.Color := $000000C1 
else
  ACanvas.Font.Color := clSilver;

{ affichage du text }
DrawMenuText(30, ACanvas, ARect, (sender as TMenuItem).Hint);
person Ken White    schedule 29.11.2011