| imho.ws |
![]() |
|
|
|
# 1 |
|
Newbie
Регистрация: 02.02.2002
Сообщения: 32
![]() |
dxBarManager и TForm.WindowMenu
Delphi
Использую dxBarManager в качестве главного меню главной формы MDI приложения. Можно ли как-то подключить WindowMenu к элементу меню dxBarManager , чтобы в него автоматом добавлялся список открытих дочерних окон? Т.е. чтобы работало навроде подключения стандартого элемента меню TMainMenu. |
|
|
|
|
# 2 |
|
::VIP::
Регистрация: 19.03.2004
Сообщения: 1 329
![]() ![]() ![]() ![]() |
Код:
The following code demonstrates organization of MDI child lists with the help of the TdxBarListItem object. If the ShowCheck property of a given class is equal to True, then at the current item (in our case it is the current MDI child form) a "check" is displayed. While selecting any window from the list, it becomes active - While destroying - it removes the corresponding string. This example assumes that the window caption contains the file name. With the change of this name, the caption and the corresponding string in the MDI child list also changes.
MainForm: TMainForm
dxBarListWindows: TdxBarListItem
dxBarListWindows.ShowCheck = True
{ . . . . . . . . }
//In MDI child (TChildForm.FormStyle = fsMDIChild):
procedure TChildForm.FormCreate(Sender: TObject);
begin
Inc(MainForm.CreatedMDICount);
Caption := 'Document' + IntToStr(MainForm.CreatedMDICount);
MainForm.dxBarListWindows.Items.AddObject(Caption, Self);
end;
procedure TChildForm.FormDestroy(Sender: TObject);
begin
with MainForm.dxBarListWindows.Items do
Delete(IndexOfObject(Self));
end;
procedure TChildForm.SetFileName(Value: string);
var
I: Integer;
begin
Caption := Value;
with MainForm.dxBarListWindows do
begin
I := Items.IndexOfObject(Self);
if (0 <= I) and (I < Items.Count) then Items[I] := Value;
end;
end;
// in MDI frame (TMainForm.FormStyle = fsMDIForm):
procedure TMainForm.dxBarListWindowsGetData(Sender: TObject);
begin
with dxBarListWindows do
ItemIndex := Items.IndexOfObject(ActiveMDIChild);
end;
procedure TMainForm.dxBarListWindowsClick(Sender: TObject);
begin
with dxBarListWindows do
if ItemIndex > -1 then
TCustomForm(Items.Objects[ItemIndex]).Show;
end;
Код:
This example illustrates how you can create a list of MDI child windows with the help of TdxBarListItem. When creating a child window, its caption is added to the item list. Upon selecting a window from the list, the dxBarListWindowsClick procedure (the OnClick event handler) is called. The OnGetData event handler is used to mark the current active child window within the list.
unit Unit1;
interface
uses
Classes, Forms, dxBar;
type
TMainForm = class(TForm)
BarManager: TdxBarManager;
dxBarButtonNewWindow: TdxBarButton;
dxBarButtonArrangeAll: TdxBarButton;
dxBarButtonNextWindow: TdxBarButton;
dxBarButtonPreviousWindow: TdxBarButton;
dxBarListWindows: TdxBarListItem;
dxBarSubItemWindow: TdxBarSubItem;
procedure dxBarButtonNewWindowClick(Sender: TObject);
procedure dxBarButtonArrangeAllClick(Sender: TObject);
procedure dxBarButtonNextWindowClick(Sender: TObject);
procedure dxBarButtonPreviousWindowClick(Sender: TObject);
procedure dxBarListWindowsGetData(Sender: TObject);
procedure dxBarListWindowsClick(Sender: TObject);
public
CreatedMDICount: Integer;
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
uses
Unit2;
// Creates a new child form
procedure TMainForm.dxBarButtonNewWindowClick(Sender: TObject);
begin
TChildForm.Create(Application);
end;
procedure TMainForm.dxBarButtonArrangeAllClick(Sender: TObject);
begin
Tile;
end;
procedure TMainForm.dxBarButtonNextWindowClick(Sender: TObject);
begin
Next;
end;
procedure TMainForm.dxBarButtonPreviousWindowClick(Sender: TObject);
begin
Previous;
end;
// The OnGetData event handler of TdxBarListItem
procedure TMainForm.dxBarListWindowsGetData(Sender: TObject);
begin
with dxBarListWindows do
ItemIndex := Items.IndexOfObject(ActiveMDIChild);
end;
// The OnClick event handler of TdxBarListItem
procedure TMainForm.dxBarListWindowsClick(Sender: TObject);
begin
with dxBarListWindows do
TCustomForm(Items.Objects[ItemIndex]).Show;
end;
end.
// The child form unit
unit Unit2;
interface
uses
Classes, Forms;
type
TChildForm = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
end;
implementation
{$R *.DFM}
uses
SysUtils, Unit1;
// Adds a child window to the child window list
procedure TChildForm.FormCreate(Sender: TObject);
begin
Inc(MainForm.CreatedMDICount);
Caption := 'Document' + IntToStr(MainForm.CreatedMDICount);
MainForm.dxBarListWindows.Items.AddObject(Caption, Self);
end;
// Removes a child window from the child window list
procedure TChildForm.FormDestroy(Sender: TObject);
begin
with MainForm.dxBarListWindows.Items do
Delete(IndexOfObject(Self));
end;
procedure TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
end.
|
|
|