我主要是想更改菜单的字体大小。
一般情况下我的代码有效{ 替换所有菜单项的 DrawItem 事件的自编事件 }
procedure TMainForm.MyMenuDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
var
ASize: TSize;
r: TRect;
begin
GetTextExtentPoint32W(Self.Canvas.Handle, 'W', 1, ASize); r := ARect;
Inc(r.Left, ASize.cx); ACanvas.Font := Self.Font;
if Selected then
begin
ACanvas.Brush.Color := clMenuHighlight;
ACanvas.Font.Color := clMenu;
end
else
begin
if TTntMenuItem(Sender).GetParentComponent is TTntMainMenu then
ACanvas.Brush.Color := clBtnFace
else
ACanvas.Brush.Color := clMenu;
ACanvas.Font.Color := clMenuText;
end; ACanvas.FillRect(ARect);
SetBkMode(ACanvas.Handle, TRANSPARENT );
DrawTextW(ACanvas.Handle, PWideChar(TTntMenuItem(Sender).Caption),
Length(TTntMenuItem(Sender).Caption), r,
DT_LEFT or DT_VCENTER or DT_SINGLELINE);
end;{ 替换所有菜单项的 MeasureItem 事件的自编事件 }
procedure TMainForm.MyMenuMeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
var
ASize: TSize;
ASize2: TSize;
begin
GetTextExtentPoint32W(Self.Canvas.Handle,
PWideChar(TTntMenuItem(Sender).Caption),
Length(TTntMenuItem(Sender).Caption),
ASize); GetTextExtentPoint32W(Self.Canvas.Handle, 'W', 1, ASize2); Width := ASize.cx + ASize2.cx;
Height := Round(ASize.cy + ASize.cy * 0.6);
end;
但是现在有一个问题。
窗口中加了一个ToolBar(ToolBar在一个CoolBar中),然后把其Menu属性设置为mmMain(TMainMenu)。 mmMain的AutoMerge属性是True。运行后,菜单可以从ToolBar中单击出来,但是显示的菜单的字体大小没有变化。也就是我的那些代码无效了。请问各位朋友,该如何解决呢?先谢谢大家关注我的帖子!
一般情况下我的代码有效{ 替换所有菜单项的 DrawItem 事件的自编事件 }
procedure TMainForm.MyMenuDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
var
ASize: TSize;
r: TRect;
begin
GetTextExtentPoint32W(Self.Canvas.Handle, 'W', 1, ASize); r := ARect;
Inc(r.Left, ASize.cx); ACanvas.Font := Self.Font;
if Selected then
begin
ACanvas.Brush.Color := clMenuHighlight;
ACanvas.Font.Color := clMenu;
end
else
begin
if TTntMenuItem(Sender).GetParentComponent is TTntMainMenu then
ACanvas.Brush.Color := clBtnFace
else
ACanvas.Brush.Color := clMenu;
ACanvas.Font.Color := clMenuText;
end; ACanvas.FillRect(ARect);
SetBkMode(ACanvas.Handle, TRANSPARENT );
DrawTextW(ACanvas.Handle, PWideChar(TTntMenuItem(Sender).Caption),
Length(TTntMenuItem(Sender).Caption), r,
DT_LEFT or DT_VCENTER or DT_SINGLELINE);
end;{ 替换所有菜单项的 MeasureItem 事件的自编事件 }
procedure TMainForm.MyMenuMeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
var
ASize: TSize;
ASize2: TSize;
begin
GetTextExtentPoint32W(Self.Canvas.Handle,
PWideChar(TTntMenuItem(Sender).Caption),
Length(TTntMenuItem(Sender).Caption),
ASize); GetTextExtentPoint32W(Self.Canvas.Handle, 'W', 1, ASize2); Width := ASize.cx + ASize2.cx;
Height := Round(ASize.cy + ASize.cy * 0.6);
end;
但是现在有一个问题。
窗口中加了一个ToolBar(ToolBar在一个CoolBar中),然后把其Menu属性设置为mmMain(TMainMenu)。 mmMain的AutoMerge属性是True。运行后,菜单可以从ToolBar中单击出来,但是显示的菜单的字体大小没有变化。也就是我的那些代码无效了。请问各位朋友,该如何解决呢?先谢谢大家关注我的帖子!
解决方案 »
- 窗口置顶
- 项目需求规格说明书
- 在调用DLL中的MDI子窗体中按回车和方向键无效
- 本人是初学者,请教大家一个比较菜的问题,希望各位帮助下小弟
- 搞了大半年ado+access,现在想转到用interbase数据库,想问几个基础性的问题?
- 求网址,高分相送!~在线等待
- 在VB和Delphi之间如何传递多维数组
- 怎樣捕捉在dos窗口里的内容信息并加以顯示
- Delphi的GD真的好,比什么都好,但是不如CSDN好,感慨一下!(NULL)同意的跟帖!
- 为什么对象--------无法正常销毁?
- stringgrid显示数据表如何换行(15)自动到第二行第一列开始,且ROM与STA还是连在一起显示不换行,急急!!!!!!!!!!!!
- 发个能用的 delphi2007的下载地址,delphi2007一定要能用!
使用TPopupMenu来代替TMenuMenu,就可以实现
加了一个PopupMenu,然后手工给ToolBar加了按钮,把按钮的DropdownMenu属性设置成PopupMenu就可以了