关于菜单(50分)

  • 主题发起人 主题发起人 hao.tong
  • 开始时间 开始时间
H

hao.tong

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样把TMenu控件加入到TControlBar控件上,望各位高人指点。
 
1,在TCONTROLBAR上面放TTOOLBAR,
2,在TTOOLBAR上放铵钮,设置不显示图,只显示文字。
3,按钮的ONDROPDOWNMENU对应弹出菜单,
4,按钮做成GROUPED。
 
e-mail给你一个demo
 
{*******************************************************}
{ }
{ Borland Delphi Visual Component Library }
{ }
{ Copyright (c) 1995,99 Inprise Corporation }
{ }
{*******************************************************}

unit MenuBar;

interface

uses
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;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TMenuBar]);
end;

{ TMenuBar }

constructor TMenuBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Flat := True;
ShowCaptions := True;
EdgeBorders := [];
ControlStyle := [csCaptureMouse, csClickEvents,
csDoubleClicks, 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.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.MenuItem := FMenu.Items;
except
Button.Free;
raise;
end;
end;
{ Copy attributes from each menu item }
for i := 0 to FMenu.Items.Count - 1 do
Buttons.MenuItem := FMenu.Items;
end;

end.
 
delphi自带的例子
delphi4/demos/docking/dockex.dpr
 
多人接受答案了。
 
后退
顶部