I have a parent and child form in Delphi. Parent form contains a TControlBar and on the top of ControlBar there are two Toolbars.
On one of the toolbars there is a button which is used to open the child form.
When child form is displayed, top partion of the form goes below the control bar and top portion of the child form goes hidden below the parent form.
I think the problem is that my child form is using full part of the parent form as the display area.
To my knowledge, I think child form should use ClientWidth and ClientHeight as the display area.
ClientWidth and Clientheight is automatically set.
I want child form to use the remaining area (other then toolbar) for display purpose.
MDI child windows are children of the MDI client window, that's the window that you refer to as the 'remaining area'. Hence they cannot go above any other window parented by the form, like controlbars, toolbars, panels etc.. Additionally, MDI child windows are not constraint with the size of this MDI client window, you can think of the MDI client as an auto-scroll window. Child windows can be moved to overrun any of the edges and a scroll bar will appear to make it possible to restore a full view on them.
If I understand correctly what you want to do, you have to maximize the child windows. You can set the WindowState property of child windows to wsMaximized to that effect.
Related
I've been following the below page in order to have a child Form that I can click on its components (such as an edit) and have proper focus:
Working with MDI Forms in Delphi
The problem now is that the components on the parent Form show on top of the child Form. If I use the SendToBack() command for those components, they completely disappear. Here is a screenshot of what happens:
EDIT:
I have a Form with buttons and a ListView that displays client info. When I click on a client, I can click a button to view or edit that client, alternatively add a new one. The Edit/Add pops up a Form where I can input the info and save it. I'm using an OnClick event for each Edit that has a SetFocus(). That gets focus on each Edit, but then all the text is selected, so I cannot click on the line and start editing text - it just overrides unless I use an arrow first.
Initially, I used regular Forms and that's where I had the focus issue. MDI fixed that, but now it's the parent components that show on top of the child.
Concerning MDI forms: that is how MDI works. The main form is not supposed to have anything else than a menu bar and optionally a toolbar, aligned alTop. The child forms use the rest of the space. Well as #RemyLebeau suggested, you can add other controls too, if you align them.
But it turned out that the actual problem with using ordinary secondary forms was that the text in an edit control on the secondary form becomes selected when you set focus to the edit control in a button click. That is easy to change, right after you set the focus to an edit control:
Edit2.SelLength := 0; // nothing selected, cursor at beginning
Edit3.SelStart := Length(Edit3.Text); // nothing selected, cursor at end of text
Based in this my working code, now i need of a ScrollBox component and a Image component inside he. Eg:
The problem now is the ScrollBox. The MDIChild Form always stays behind, you can test, changing ScrollBox Align (None/Client) property.
Then what is need to MDIChild Form stay above of ScrollBox?
The MDI client window that hosts the MDI child forms is the bottom most window of the MDIForm's content. You can't make MDI child forms appear on top of anything else, because literally everything else placed on the MDIForm is on top of the MDI client window and thus on top of the child forms.
Is there a way to show MDI child forms (FormStyle = fsMDIChild) on the main form that has a frame with Align = alClient?
Creating a frame on the main form:
Frame := TfrCalendar.Create(Self);
Frame.Parent := Self;
Creating MDI child form on the main form:
if Assigned(FMDIRef)
then
FMDIRef.BringToFront
else begin
FMDIRef := TFReference.Create(Application);
FMDIRef.Show;
end;
After this, the child form is not visible. If you do not create a frame, the form is visible. If you first show the child form, and then create a frame on the main form, then the child form becomes invisible again.
The issue here is that your frame is competing for space with the MDI client window. The MDI client window is the window which is parent to the MDI child windows.
In your scenario the frame consumes all remaining client area inside the main window, thus leaving no space for the MDI client window.
What you are attempting is not possible. The MDI client window has to go somewhere, and you must leave it some room.
Depending on what your actual goal is, different solutions are available:
If the frame is intended to be visible always, then use alTop. The remaining space below it will be available to the MDI client window.
If you wish to show an image on the MDI client window to act as a background, refer to my answer here: https://stackoverflow.com/a/15137740/505088
hi
I have a form in which i placed another form as MDI ,on moving the MDI form (Top,Bottom,Left,Right)it goes inside the boundaries of main form so the Mdi gets hidden.
i want to restrict the MDI form to move when it touches the form boundaries.
You need to capture the OnMove event for your child forms, and in that handler you need to make sure your child form's window rect is within the parent's boundary. If not you need to adjust the location of the child form.
An example of how to do this can be found here.
I have page control in main form and page controls in child form , I
place the child form inside the main form by using docking features.
I am not using MDI style
Now both forms have tabs in page control and I need to merge the child form
tabs into the main form page control, what is the best way to do that?
The simplest and best way to handle multiple tabs on a page control is usually with Frames. Take the contents of each tab and factor them out into an individual frame for each tab. Move any shared components, state and code to a data module. Then just place those frames on the tab sheets of your page control.
This is a fairly simple approach that may or may not suit your needs.
For each child tab page you need to merge:
Create a tab in the main form page
control corresponding to the child
tab
Iterate over the Controls in the
child tab and change the Parent
property to the tab page you just
created
You do not need to deal with controls that are children of other controls. e.g. if you have a groupbox in your child tab, then changing it's parent will bring both it and all controls within it to the new parent.
If you need to be able to "unmerge" your tabs at any point then you will need to devise some mechanism to keep track of where the controls came from so you can restore the original Parent as/when needed.
To make things slightly easier you could place a TPanel in the child tabs, with it's Align property set to alClient. Place all the controls in the tab on that panel and then when you need to merge/unmerge you need only set the Parent of the panel control.
I just tried
procedure TForm1.Button1Click(Sender: TObject);
begin
while Form2.PageControl1.PageCount > 0 do
Form2.PageControl1.Pages[0].PageControl := PageControl1;
end;
and it worked fine. Am I missing something obvious, or why is everybody giving such sophisticated solutions? :-)