BorderColor:TColor; //邊框顏色FillColor:TColor; //未選中填充顏色TextColor:TColor; //未選中字體顏色SelectTextColor:TColor; //選中字體顏色SelectFillColor:TColor; //選中填充顏色SideBuffer:Integer; //邊框寬度procedure TForm1.FormCreate(Sender: TObject); beginBorderColor:=clRed;FillColor:=clWhite;TextColor:=clBlue;SelectTextColor:=clYellow;SelectFillColor:=clGray;SideBuffer:=1; end;procedure TForm1.Button1Click(Sender: TObject); varpo:TPoint; beginpo.X:=TControl(Sender).Left;po.Y:=TControl(Sender).Top+TControl(Sender).Height;po:=ClientToScreen(po);PopupMenu1.Popup(po.X,po.Y); end;procedure TForm1.N11DrawItem(Sender: TObject; ACanvas: TCanvas;ARect: TRect; Selected: Boolean); varFocusRectBorder:TRect;FocusRectFill:TRect;TextRect:TRect;MenuItem:TMenuItem;Title:string; beginTextRect:=ARect;MenuItem:=(Sender) as TMenuItem;Title:=MenuItem.Caption;// 填充菜單項背景顏色ACanvas.Brush.Color:=FillColor;ACanvas.FillRect(ARect);//沒有菜單內容就返回。if Title='' then exit;//選中菜單if selected thenbegin//畫菜單外面邊框。FocusRectBorder:=ARect;ACanvas.Brush.Color := BorderColor;ACanvas.FrameRect(FocusRectBorder);//填充菜單內部FocusRectFill := ARect;//設置內部邊框比外面要小點。FocusRectFill.Top := FocusRectFill.Top + SideBuffer;FocusRectFill.Left := FocusRectFill.Left + SideBuffer;FocusRectFill.Right := FocusRectFill.Right - SideBuffer;FocusRectFill.Bottom := FocusRectFill.Bottom - SideBuffer;//設置為高度顯示的顏色ACanvas.Brush.Color := SelectFillColor;ACanvas.FillRect(FocusRectFill);//設置當菜單選中后字體的顏色ACanvas.Font.Color := SelectTextColor;ACanvas.Font.Style := ACanvas.Font.Style+[fsBold];endelse //沒有選中begin//設置當菜單字體的顏色ACanvas.font.Color := TextColor;ACanvas.Font.Style := ACanvas.Font.Style+[fsBold];end;//畫圖標if MenuItem.ImageIndex<> -1 thenbeginACanvas.Font.Style := ACanvas.Font.Style-[fsBold];ImageList1.Draw(ACanvas,0,(MenuItem.ImageIndex)*27,MenuItem.ImageIndex);end;//寫文字TextRect.Left := TextRect.Left+5+24;TextRect.Top := TextRect.Top + 1;DrawText(ACanvas.Handle,PChar(Title),Length(title),TextRect,0); end;
?