Delphi中Menu设置Images属性后快捷按键下划线被隐藏解决方法
现象:
MainMenu设置Images属性后,看不到快捷按键的下划线,如:新建(&N)
分析:
VCL中Menus.pas单元的代码,看到如下语句
procedure TMenuItem.AdvancedDrawItem(ACanvas: TCanvas; ARect: TRect;
State: TOwnerDrawState; TopLevel: Boolean);
//...
if Win2K and (odNoAccel in State) then
DrawStyle := DrawStyle or DT_HIDEPREFIX;
//...
DT_HIDEPREFIX就是隐藏下划线 //用DrawText()测试一下就知道
在设置Images属性后(odNoAccel in State)为真
看来需要自绘菜单,响应OnAdvancedDrawItem事件
当然,自绘菜单的代码写起来就多了,还好AdvancedDrawItem()声明在protected部分
我们可以通过继承TMenuItem来访问AdvancedDrawItem()
type
TMenuItemAccess = class(TMenuItem);
现在就要想办法使那个条件不成立,先从Win2K入手
当Images设置后"Win2K and (odNoAccel in State)"这个条件成立
分析单元中Win2K变量是这样得到的
Win2K := (Win32MajorVersion > 4) and (Win32Platform = VER_PLATFORM_WIN32_NT);
那么我们就可以通过修改Win32MajorVersion或者Win32Platform常量使其不成立
参考代码:
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
ImageList1: TImageList;
MenuItemFile: TMenuItem;
MenuItemNew: TMenuItem;
MenuItemOpen: TMenuItem;
PopupMenu1: TPopupMenu;
MenuItemCopy: TMenuItem;
MenuItemPaste: TMenuItem;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure MenuItemAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; State: TOwnerDrawState);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TMenuItemAccess = class(TMenuItem);
procedure TForm1.MenuItemAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; State: TOwnerDrawState);
var
vWin32Platform: Integer;
begin
vWin32Platform := PInteger(@Win32Platform)^;
PInteger(@Win32Platform)^ := -1;
TMenuItemAccess(Sender).OnAdvancedDrawItem := nil;
try
TMenuItemAccess(Sender).AdvancedDrawItem(ACanvas, ARect, State,
TMenuItemAccess(Sender).GetParentComponent is TMainMenu);
finally
TMenuItemAccess(Sender).OnAdvancedDrawItem := MenuItemAdvancedDrawItem;
PInteger(@Win32Platform)^ := vWin32Platform;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
begin
for I := 0 to ComponentCount - 1 do
if Components[I] is TMenuItem then
TMenuItem(Components[I]).OnAdvancedDrawItem := MenuItemAdvancedDrawItem
else if Components[I] is TMenu then
TMenu(Components[I]).OwnerDraw := True;
end;
http://blog.csdn.net/zswang/article/details/1653340
Delphi中Menu设置Images属性后快捷按键下划线被隐藏解决方法的更多相关文章
- MVC dropdownlist 后端设置select属性后前端依然不能默认选中的解决方法
-----------------------------------来自网上的解决方法--------------------------------------------- ASP.Net MV ...
- nginx 自动忽略request中header name包含下划线参数的解决方法
使用nginx过程中遇到了个问题,就是request中的header name中如果包含下划线会自动忽略掉,导致服务器接收不到该字段的内容,以下为解决方法: nginx默认request的header ...
- dedecms设置文章分页后,标题会带有序号的解决方法
至于删除分页后标题后面的序号,找到include/arc.archives.class.php 打开,找到 if($i>1) $this->Fields['title'] = $this- ...
- Delphi中TStringList类常用属性方法详解
TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 先把要讨论的几个属性列出来: 1.CommaText 2.Delim ...
- ComboBox控件“设置 DataSource 属性后无法修改项集合”的解决【转】
编写Winform程序,遇到comboBox的绑定事件和索引项变更事件的冲突问题,就是“设置 DataSource 属性后无法修改项集合”的错误问题,网上查了很多,大多说在索引项变更是进行非空判断,还 ...
- C# LIstbox 解决WinForm下ListBox控件“设置DataSource属性后无法修改项集合”的问题
解决WinForm下ListBox控件“设置DataSource属性后无法修改项集合”的问题 分类: winform2008-05-24 02:33 2592人阅读 评论(11) 收藏 举报 winf ...
- 解决WinForm下ListBox控件“设置DataSource属性后无法修改项集合”
解决WinForm下ListBox控件“设置DataSource属性后无法修改项集合” 最近更新: 2013-2-15 587 很少写WinForm程序第一次使用ListBox控件就遇到了比 ...
- 元素设置disabled属性后便无法向后台传值
元素设置disabled属性后便无法向后台传值
- 解决BootstrapTable设置height属性后,表格不对齐的问题
解决BootstrapTable设置height属性后,表格不对齐的问题 2018年03月06日 09:56:54 nb7474 阅读数 5920 一般在使用BootstrapTable 插件 ...
随机推荐
- android之照相、相冊裁剪功能的实现过程
今天无聊做了一些照相.相冊裁剪功能,希望能够帮到大家! 不多说了,贴代码实际一点: 首先是XML: <ImageButton android:id="@+id/imageButton1 ...
- Green the world :使用monkey_patch
eventlet的monkey_patch 用于绿化一些python的模块,看看以下的样例就明确了 urls = ["http://www.haha.mx/joke/1292935" ...
- uva 11552 Fewest Flops 线性dp
// uva 11552 Fewest Flops // // 二维线性dp // // 首先,在该块必须是相同的来信.首先记录每块有很多种书 // 称为是counts[i]; // // 订购f[i ...
- 《Java并发编程实战》第十二章 测试并发程序 读书笔记
并发测试分为两类:安全性测试(无论错误的行为不会发生)而活性测试(会发生). 安全測试 - 通常採用測试不变性条件的形式,即推断某个类的行为是否与其它规范保持一致. 活跃性測试 - 包含进展測试和无进 ...
- 取消Jquery mobile自动省略的文本
在使用jquery moblie做移动客户端app时,listview控件下的列表文本不能完全显示,只能显示一行,超过字数jquery mobile会自动用省略号代替.很是纠结啊. 最后在一个岛国网站 ...
- Entity Framework加载数据的三种方式。
MSDN文章Loading Related Entities 有 Eagerly Loading Lazy Loading Explicitly Loading 三种方式. 而看到查询中包含Inclu ...
- zcelib - One cplusplus C++ crossplatform library use for develop server,similar to ACE.
zcelib - One cplusplus C++ crossplatform library use for develop server,similar to ACE.OS适配层,为了适应WIN ...
- 使用openssl工具生成密钥
下载Openssl工具 进入OpenSSL工具,输入以下命令. OpenSSL> genrsa - #生成私钥 OpenSSL> pkcs8 -topk8 -inform PEM -in ...
- XF 开关控件
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http:/ ...
- WPF BorderBrush BorderThickness
基本上所有的控件都可以设置BorderBrush BorderThickness 例如TextBox,Button