BCB自绘菜单

1.N13AdvancedDrawItem 绘制子菜单
		TRect tempRect;//临时矩形区域
		TMenuItem *pItem = dynamic_cast<TMenuItem *>(Sender);
		if(!pItem) return;
		AnsiString Caption = pItem->Caption;
		ACanvas->Brush->Color = clWhite;
		ACanvas->FillRect(ARect);
		tempRect = Rect(ARect.left,ARect.top,21,ARect.Bottom);
		ACanvas->Brush->Color = TColor(RGB(249,248,244));;
		ACanvas->FillRect(tempRect);
		TCustomImageList *ImageLst = new TCustomImageList(this);
		TIcon *DrawIcon = new TIcon();
		if(Caption=="-")
		{
			 ACanvas->Pen->Color=TColor(RGB(208,201,161));
			 ACanvas->MoveTo(21,ARect.top+(ARect.Bottom-ARect.top)/2);
			 ACanvas->LineTo(ARect.right,ARect.top+(ARect.Bottom-ARect.top)/2);
			 return;
		}
		ImageLst = pItem->GetImageList();
		ImageLst->GetIcon(pItem->ImageIndex,DrawIcon);
		if((State.Contains(odSelected)==true)&&(State.Contains(odDisabled)==false))
		{
			 ACanvas->Brush->Color = TColor(RGB(198,211,239));
			 ACanvas->Pen->Color = TColor(RGB(49,105,198));
			 ACanvas->Rectangle(ARect.left,ARect.top,ARect.right,ARect.Bottom);
			 if(ImageLst!=NULL)
			 {
					ACanvas->Draw(ARect.left,ARect.top,DrawIcon);
			 }
			 ACanvas->Font->Color = clBlack;
		}
		else if(State.Contains(odDisabled)==true)
		{
				ACanvas->Font->Color = TColor(RGB(208,201,161));
		}
		if(pItem->Checked)
		{
				ACanvas->Brush->Color = TColor(RGB(198,211,239));
				ACanvas->Pen->Color = TColor(RGB(49,105,198));
				ACanvas->Rectangle(ARect.left+1,ARect.top+1,20,ARect.Bottom-1);
		}
		if(ImageLst!=NULL)
		{
				ACanvas->Draw(ARect.left,ARect.top-1,DrawIcon);
		}
		DrawIcon->Free();
		ACanvas->Brush->Style = bsClear;
		ARect.left+=30;
		ARect.top+=5;
		DrawText(ACanvas->Handle,Caption.c_str(),-1,&ARect,DT_LEFT);
		AnsiString ShortCutText = ShortCutToText(pItem->ShortCut)+" ";
		DrawText(ACanvas->Handle,ShortCutText.c_str(),-1,&ARect,DT_RIGHT);

 

 

 

 

2  绘制主菜单

void __fastcall TMainFm::MenuOwerDrawAdvancedDrawItem(TObject *Sender, TCanvas *ACanvas,
					TRect &ARect, TOwnerDrawState State)
{
		TRect tempRect;//临时矩形区域
		TMenuItem *pItem = dynamic_cast<TMenuItem *>(Sender);
		if(!pItem) return;
		ACanvas->Brush->Color = clBtnFace;
		ACanvas->FillRect(ARect);
		AnsiString Caption = pItem->Caption;
		tempRect = Rect(ARect.left,ARect.top,ARect.right,ARect.Bottom);
		if(State.Contains(odHotLight)&&!State.Contains(odDisabled))
		{
				ACanvas->Brush->Color =  TColor(RGB(198,211,239));
				ACanvas->Pen->Color =  TColor(RGB(49,105,198));
				ACanvas->Rectangle(ARect.left,ARect.top+1,ARect.right,ARect.Bottom);
		}
		else if ((State.Contains(odSelected)==true)&&(State.Contains(odDisabled)==false))
		{
				ACanvas->Brush->Color = TColor(RGB(236,233,216));
				ACanvas->Pen->Color = TColor(RGB(138,134,122));
			 	ACanvas->Rectangle(ARect.left,ARect.top+1,ARect.Right,ARect.Bottom);
		}
		else if(State.Contains(odDisabled)==true)
		{
				ACanvas->Font->Color = TColor(RGB(208,201,161));
		}
		tempRect.top+=3;
		DrawText(ACanvas->Handle,Caption.c_str(),-1,&tempRect,DT_CENTER);
}


 


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值