Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to add a button to a TToolBar for each MDI child form created Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
03-Oct-02
Category
Others
Language
Delphi 2.x
Views
102
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I want to create a TToolBar that will have corresponding buttons to the MDI 
children in my form, so that the user can switch between the children by clicking 
on the buttons - not going through the MDI menu. How do I do that ? Adding a button 
on MDI child creation, deleting the button when the corresponding window is closed, 
respond to CTRL+TAB, CTRL+F4 messages and so on.

Answer:

I did something like this. In my mdi parent form, I have three public procedures:

procedure addwindow(Sender: TForm; const Str: string);
procedure delwindow(Sender: TObject);
procedure activatewindow(Sender: TObject);

In the child form's oncreate, ondestroy, onformactivate, I call the corresponding 
parent's method sending self as the parameter. I store sender in the toolbutton's 
tag property so I know which button corresponds to which child window.

The code looks like this (TXnewsFrame is the mdi parent form; Taskbar is my 
toolbar).

1   { str is window's caption }
2   
3   procedure TXnewsFrame.AddWindow(Sender: TForm; const Str: string);
4   begin
5     with TToolButton.Create(TaskBar) do
6     begin
7       AutoSize := true;
8       Left := TaskBar.Width;
9       Parent := TaskBar;
10      Style := tbsCheck;
11      Grouped := true;
12      AllowAllUp := false;
13      OnClick := TaskClick;
14      Caption := Str;
15      Hint := Str;
16      Tag := Integer(Sender); { store form in button's tag }
17      Down := true;
18    end;
19    TaskBar.Update;
20  end;
21  
22  procedure TXnewsFrame.DelWindow(Sender: TObject);
23  var
24    i: integer;
25  begin
26    with TaskBar do
27      for i := ButtonCount - 1 downto 0 do
28        if TForm(Buttons[i].Tag) = Sender then
29        begin
30          Buttons[i].Free;
31          break;
32        end;
33  end;
34  
35  procedure TXnewsFrame.ActivateWindow(Sender: TObject);
36  var
37    i: integer;
38  begin
39    with TaskBar do
40      for i := ButtonCount - 1 downto 0 do
41        with Buttons[i] do
42          if TForm(Tag) = Sender then
43          begin
44            Down := true;
45            break;
46          end;
47  end;
48  
49  { taskbar's onclick event handler }
50  
51  procedure TXnewsFrame.TaskBarClick(Sender: TObject);
52  var
53    F: TForm;
54    i: integer;
55  begin
56    if (sender is TToolButton) then
57    begin
58      F := TForm(TComponent(Sender).Tag);
59      with F do
60        if (F <> Self.ActiveMDIChild) or not Visible then
61        begin
62          BringToFront;
63          if WindowState = wsMinimized then
64            ShowWindow(Handle, SW_RESTORE);
65        end;
66    end;
67  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC