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