菜单拖动事件 请问DELHPI,中能否做到像WINDOWS一样的菜单拖动效果,我发现POPUPMENU和MAINMENU都没有拖动事件,请问各位朋友能做到吗。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DELPHI中的,TMainMenu和TPopUpMenu都是不可视控件,不可视控件可以移动吗?当然不行!有空看看代码Menus单元的代码,类只不过是封装了关于菜单的API,而和菜单本身无关!想要移动当然只能是可视控件!找个能显示下拉菜单的载体(如TToolBar),把默认的菜单隐藏! 非常感谢ehom(?!) 兄的热情支持但小弟水平巨臭,能否给出一个例子参考在菜单上的拖动,比如两个菜单的Item 能够交换位子犹如WIndows开始菜单一样 unit MenuBar;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ToolWin, ComCtrls, Menus;type TMenuBar = class(TToolBar) private FMenu: TMainMenu; procedure SetMenu(const Value: TMainMenu); protected procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override; public constructor Create(AOwner: TComponent); override; published property EdgeBorders default []; property Menu: TMainMenu read FMenu write SetMenu; end;procedure Register;implementationprocedure Register;begin RegisterComponents('Samples', [TMenuBar]);end;constructor TMenuBar.Create(AOwner: TComponent);begin inherited Create(AOwner); Flat := True; ShowCaptions := True; EdgeBorders := []; ControlStyle := [csCaptureMouse, csClickEvents, csMenuEvents, csSetCaption];end;procedure TMenuBar.GetChildren(Proc: TGetChildProc; Root: TComponent);beginend;procedure TMenuBar.SetMenu(const Value: TMainMenu);var i: Integer; Button: TToolButton;begin if FMenu = Value then exit; if Assigned(FMenu) then for i := ButtonCount - 1 downto 0 do Buttons[i].Free; FMenu := Value; if not Assigned(FMenu) then exit; for i := ButtonCount to FMenu.Items.Count - 1 do begin Button := TToolButton.Create(Self); try Button.AutoSize := True; Button.Grouped := True; Button.Parent := Self; Buttons[i].MenuItem := FMenu.Items[i]; except Button.Free; raise; end; end; for i := 0 to FMenu.Items.Count - 1 do Buttons[i].MenuItem := FMenu.Items[i];end;end.现成控件会用吗?加上TCoolBar如果要移出为窗体,找Dock相关资料看 啊?理解错误!Window开始菜单啊,呵呵,上当了,那根本就不是传统意义上的菜单!看看它的CLASS,ToolBarWindow32!用普通菜单是做不到的! 不管怎么,还是很谢谢ehom兄了,我会另开贴子给分的,来接喔! 使用AssingFile关联好一个文件后,有什么办法能够直接定位到文件的最后一行? 续(重酬!!bde连接access问题!) 一个菜单控制的问题(在线等待!问题解决马上结分。急......) 奇怪?怪怪怪.为什么在子函数内使用就不行 求3DES加密算法(CBC模式,采用PKCS5-Padding填充方式) 怎样看到dll文件的内容 请问这样的SQL怎么写? 高手帮忙,这个功能怎么实现? SOS!!大伙救我!!一个简单的报表问题!! .db数据库查询的问题 看一下这个语句的问题? TClientDataset数据刷新的问题,提出有建设性建议的有分
但小弟水平巨臭,能否给出一个例子参考
在菜单上的拖动,比如两个菜单的Item 能够交换位子
犹如WIndows开始菜单一样
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ToolWin, ComCtrls, Menus;type
TMenuBar = class(TToolBar)
private
FMenu: TMainMenu;
procedure SetMenu(const Value: TMainMenu);
protected
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
public
constructor Create(AOwner: TComponent); override;
published
property EdgeBorders default [];
property Menu: TMainMenu read FMenu write SetMenu;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Samples', [TMenuBar]);
end;constructor TMenuBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Flat := True;
ShowCaptions := True;
EdgeBorders := [];
ControlStyle := [csCaptureMouse, csClickEvents, csMenuEvents, csSetCaption];
end;procedure TMenuBar.GetChildren(Proc: TGetChildProc; Root: TComponent);
begin
end;procedure TMenuBar.SetMenu(const Value: TMainMenu);
var
i: Integer;
Button: TToolButton;
begin
if FMenu = Value then exit;
if Assigned(FMenu) then
for i := ButtonCount - 1 downto 0 do
Buttons[i].Free;
FMenu := Value;
if not Assigned(FMenu) then exit;
for i := ButtonCount to FMenu.Items.Count - 1 do
begin
Button := TToolButton.Create(Self);
try
Button.AutoSize := True;
Button.Grouped := True;
Button.Parent := Self;
Buttons[i].MenuItem := FMenu.Items[i];
except
Button.Free;
raise;
end;
end;
for i := 0 to FMenu.Items.Count - 1 do
Buttons[i].MenuItem := FMenu.Items[i];
end;end.现成控件会用吗?加上TCoolBar如果要移出为窗体,找Dock相关资料看