How can I hide the toolbar of the main form automatically when the mdichildform subform is displayed ???

Source: Internet
Author: User
How can I hide the toolbar of the main form automatically when the mdichildform subform is displayed ??? Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061220145944198.html
How does one automatically hide the toolbar of the main form mdiform when the mdichildform subform is displayed ???

???

Each sub-form is used as the toolbar.
In this way, the toolbar of the subform is displayed at the top of the main form...

Otherwise, you can search for the action with the same name.
Example Code :
// When the main form's main toolbar button is pressed, find the action with the same name in the child form and execute
Procedure tfrmmain. bindactiveformexecute (Sender: tobject );
VaR
Activeform: tform;
Action: taction;
Begin
Action: = nil;

// Determine whether there is a dock window on the current page
If (pagecontrol1.pagecount> 0) and
(Pagecontrol1.activepage. controlcount> 0) and
(Pagecontrol1.activepage. controls [0] Is tform) then
Begin
Activeform: = pagecontrol1.activepage. controls [0] As tform;

// Find the current action
If sender is taction then action: = findsameaction (activeform, sender as taction );
End;

// Execute the binding process
If assigned (Action) then action. Execute;
End;


// Update the enabled validity of the action in the main form
Procedure tfrmmain. bindactiveformupdate (Sender: tobject );
VaR
Activeform: tform;
Mainaction, Action: taction;
Begin
Action: = nil;

// Search for the active state of the current shortcut menu
If (pagecontrol1.pagecount> 0) and
(Pagecontrol1.activepage. controlcount> 0) and
(Pagecontrol1.activepage. controls [0] Is tform) then
Begin
Activeform: = pagecontrol1.activepage. controls [0] As tform;
Action: = findsameaction (activeform, sender as taction );
End;

If assigned (Action) then
Begin
Action. update;
Mainaction: = (sender as taction );

// Set the action attribute
Mainaction. Enabled: = action. enabled;
If action. Caption <> mainaction. Caption then action. Caption: = mainaction. Caption;
If action. Shortcut <> mainaction. Shortcut then action. Shortcut: = mainaction. Shortcut;
End else (sender as taction). Enabled: = false;
End;

// Search for actions with the same name in the subform
Function tfrmmain. findsameaction (Form: tform; Action: taction): taction;
VaR
Actionlist: tactionlist;
I, J: integer; // temporary Addition
Frmsub: tform; // temporary Addition
Begin
Result: = nil;
Actionlist: = nil;

// Actionlist: = tactionlist. Create (NiL); // useless
Try
// All elements in the cyclic enumeration window
For I: = 0 to form. componentcount-1 do
Begin
// Determine whether the window is a subwindow
If form. components [I] Is tform then
Begin
Frmsub: = (Form. components [I] As tform); // Record Form sub-elements

// Search for tactionlist in the subwindow cyclically
For J: = 0 to frmsub. componentcount-1 do
Begin
If frmsub. components [J] Is tactionlist then
Begin
Actionlist: = frmsub. components [J] As tactionlist;
Break;
End;
End;
End;

// Determine whether the retrieved control is a tactionlist
If form. components [I] Is tactionlist then
Begin
Actionlist: = form. components [I] As tactionlist;
Break;
End;
End;

// No exit process found
If assigned (actionlist) then
Begin
// Search for the corresponding action in a loop
For I: = 0 to actionlist. actioncount-1 do
Begin
If (actionlist [I] As taction). Name = action. name then
Begin
Result: = actionlist [I] As taction;
Break;
End;
End;
End;
Finally
// Actionlist. Free; // useless
End;
End;
The onexecute of the action in the actionlist in the main form is bound to the bindactiveformexecute function. When the subform is opened, click the toolbar of the main form to find the action with the same name to execute its onexecute
Onupdate should be bound to the bindactiveformupdate process. In this way, the toolbar buttons of the main form are valid and the actions with the same name as the subform.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.