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;