Hiding some attributes i.e. textboxes, labels in parent form - mdi

m using a MDI child form and want it to display when a button from its parent form is clicked, at the same time i want that when the child form appears it should be placed such that some of the attributes of the parent form i.e. picture box is shown while others as labels and textboxes are hidden. Is this possible and how?

Not sure what language or framework you are using. And I don't get what you mean position so some attributes are hidden.
What I do know is that you should easily be able to hide those objects when you click the button, in C# for example myLabel.Visible = false; or you can use myLabel.Hide() and .Show()

You could put the controls, which should be always visible on a separate form and make it top-most, so that it always stays on top of every other form.
See this for an example: How to make a window stay on top

Related

Parent components show over child form

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

Delphi proper use of TMultiView

As you know there is a new component called TMultiView that can be user as navigation drawer if you set the mode to Drawer. Let's say that I have a drawer with 5 buttons inside and each of them, when clicked, shows in the main form a particular layout.
I was thinking that I could add to my form a lot of TLayout and set their visibility to false. Then, when I click in a button of the Drawer, I set the respective visibility to true/false.
I am not sure if this is a good way to structure the app. Do you have any suggestion?
One approach is to place a TabControl on the form. As you have 5 buttons and want 5 different "layouts" you would add 5 tabs to the TabControl. On each tab place a TLayout.
At design time it is straight forward to design each of the layouts.
At run time switch to the appropriate layout.

How to add a label and edit controls inside an already existing groupbox in a design mode using delphi

As one of my requirements, I have to add a label and edit field to an existing groupbox in delphi. But how many times, i add a label inside an existing groupbox it disappears or it wont get added. Is there an alternative way to do this?
Am not sure why but am able to add edit but not label
I'm going to take a wild guess here. You are adding new components without first selecting the group box in the design surface. When you do that the component becomes a child of the form and disappears beneath other controls.
Here's how to do it:
Click on the group box on the form design surface,
then double click on the label in the palette.
Alternatively:
Single click on the label in the palette,
then single click on the group box on the form design surface.
If you do get the component parent/child relationships messed up, you can inspect them in the Object TreeView (open this from the View menu). If the relationships are wrong, drag the child controls around in the Object TreeView, and drop them into their desired parents.

Merge tabs from child form into main form

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? :-)

form main + form child stacking issue

I am using main form and child forms.
If I open 2nd child form with
TMYForm.Create(nil);
It does not stack it on the 1st child form top.
Is there any way for 2nd and X'th child form to appear in exact same position as 1st child form?
Or I need to destroy old child form while creating new one (as stacking is done automatically)?
That is the expected behavior. Without specifying otherwise, Forms will open on the right and down from the position of the previously opened.
If you want to control the position of your form, change its Position property to poDesigned, but you have to set its Top and Left properties to ensure it'll be visible.
Or you can used some presets: poDesktopCenter, poMainFormCenter, poOwnerFormCenter or poScreenCenter.
Try putting this:
TMYForm.Position:=poMainFormCenter;
or
TMYForm.Position:=poOwnerFormCenter;
Before TMYForm.Create(nil);
-S
If you have references to the child forms, use Form2.BoundsRect := Form1.BoundsRect

Resources