2011-11-29 12 views
3

我有這個代碼用於在Delphi中對MainMenu進行彩色化。它適用於OnDrawItem事件,但我甚至需要一些東西,我不知道如何才能做到這一點。我想是一個MainMenu項目的字體,如果該項目成爲禁用(啓用= 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; 

回答

2

它應該是相當容易:

{ 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); 
相關問題