如何在菜单的左边加一个长方形的图片,就像WINDOWS的开始菜单?
如何在菜单的左边加一个长方形的图片,就像WINDOWS的开始菜单?
[解决办法]
1、用第三方的菜单控件
2、自绘(不推荐)
[解决办法]
关注一下
[解决办法]
Graphics::TBitmap *bmp; // Line 1
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
bmp = new Graphics::TBitmap; // Line 2
bmp-> LoadFromFile( "Bar.bmp "); // Line 3
// (bmp = new Graphics::TBitmap)-> LoadFromFile( "Bar.bmp ");
// 这样写又可以省一行,哈哈,不过怕新手看不明白 :)
}
//---------------------------------------
void __fastcall TForm1::BarItemMeasureItem(TObject *Sender,
TCanvas *ACanvas, int &Width, int &Height)
{
Width += 2; // Line 4
Height *= BarItem-> Parent-> Count - 1; // Line 5
}
//---------------------------------------
void __fastcall TForm1::BarItemDrawItem(TObject *Sender, TCanvas *ACanvas,
TRect &ARect, bool Selected)
{
ACanvas-> Draw(0, 0, bmp); // Line 6
}
//---------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
delete bmp; // Line 7
}
//--------------------------
[解决办法]
问题还存在啊,我还想LZ来揭帖呢.期待...
[解决办法]
引自about:delphi programming,详情见:http://delphi.about.com/od/vclusing/a/owner_drawing.htm
procedure TForm1.mnuBoldDrawItem (Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean) ;
var
ImgID: integer;
begin
if Selected then
ACanvas.Brush.Color := clHighlight
else
ACanvas.Brush.Color := clMenu;
{move the rect to make place for the side bar}
ARect.Left := 20;
ACanvas.FillRect(ARect) ;
if mnuBold.Checked then
ImgID := 1 {thumb up in the ImageList}
else
ImgID := 0; {thumb down in the ImageList}
ImageList1.Draw(ACanvas,22,ARect.Top + 2,ImgID) ;
ACanvas.Font.Style := [fsBold];
{user defined text drawing function:}
DrawItemText(45,ACanvas,ARect, 'Bold ') ;
end;