How to control parent form from modally called child form - c#

Is it possible to control the parent form from a modal child form?
My only idea is to close the parent form and show child form via ChildForm.Show() and not ChildForm.ShowDialog(parentform), can I control parent form from modally displayed child form?
How to refresh a parent form automatically upon saving the update on the child form?

You can access the parent (Owner) form by using Owner property. If you show the dialog using:
childForm.ShowDialog(this);
(this will be the form from where you are showing the dialog)
then in the dialog:
this.Owner.BackColor=System.Drawing.Color.Coral;
This will change the background colour of the parent form immediately.
ParentForm is available in the context of MDIForm context.

Related

How to change the active mdi child?

Well this maybe is simple but I cannot nail it.
I have a win forms application with a from as Mdi Container with n mdi childs.
How to set ActiveMdiChild ?
For example i have 4 mdi childs (0,1,2,3) and i want to pass the appropriate data to each one...but only the active gets the data..
To activate a specific MDI child, you can use ActivateMdiChild method of the MDI parent and pass the child to activate. For example:
this.ActivateMdiChild(this.MdiChildren[0]);
ActivateMdiChild (Form)
Activates the MDI child of a form.
If the form parameter is already the active MDI child form, then the
ActivateMdiChild method simply returns. If form is not null, then it
is set to be the active MDI child form. Whether the form parameter is
null or not, ActivateMdiChild raises the MdiChildActivate event.
You can do this:
foreach (Form frm in this.MdiChildren)
{
if (frm is Form1)
{
Form frmChild = this.ActiveMdiChild;
frmChild .Show();
}
}
If the child have different form names, you can just have if statement to check if this is the form you are checking then set it as your acitvemdichild.

Minimizing child modal form without minimizing main form and recover child modal form

I have a modal form which will do some long operation, during that operation user wants to minimize the modal form and do some other activity in Main form and the progress bar for modal form is shown in Main forms status bar
When user clicks on the status bar then modal form should appear to the user.
Summarize:
We have Main Winform and Child Modal Winform
The child modal form has some long operation which is shown by Progress Bar
If user minimizes the Child Form. It completely minimizes the Main From
But user want to minimize only the Child Form and do some operation in Main form
I tried two approaches
Hiding the modal from on minimize event. The Child form is hidden
then i am unable to recover the child form instance show it back from
the main form since the object of modal form is disposed
using (Form1 reportForm = new Form1(dbConnection))
{
reportForm.ShowDialog();
}
If i do the minimize of modal form it minimizes the main form also.
In one stackoverflow it is mentioned that modal form is minimized then main form also will minimize Main form, this is right behaviour by design.
Please give me an approach for this issue.
The whole point of a modal form is that the user can't do something else in the parent form.
Assuming your long running operation depends on input from the modal form you should do this:
Keep the form modal
Move the long operation into a backgroundworker
start the background worker upon closing of the modal form
open new non-modal form to show the progress from the background worker.
Try this link...
https://msdn.microsoft.com/en-us/library/7aw8zc76(v=vs.110).aspx
protected void MDIChildNew_Click(object sender, System.EventArgs e){
Form2 newMDIChild = new Form2();
// Set the Parent Form of the Child window.
newMDIChild.MdiParent = this;
// Display the new form.
newMDIChild.Show();
}

How to show new form without disabling the parent form?

I have shown a new form in button click on parent form like below,
Here the background parent form gets disabled when a new child form is activated.
Is there any available options to show the child form without disabling the parent form?
Regards,
The Show function shows the form in a non modal form. This means that you can click on the parent form.
ShowDialog shows the form modally, meaning you cannot go to the parent form
Application.Run() runs the main parent form, and makes that form the main form. Application.Run() is usually found in main.
If it is fully disabled (no interaction possible), you are using .ShowDialog() on the child form instead of .Show(). If you use .Show() you will be able to use both forms
Example:
ChildForm childForm = new ChildForm();
childForm.Show();
after you open the new form and call this.Activate(); it will refocus on the parent window, but this will cause it to loose focus for a fraction of a second

Child form's controls not displaying correctly

I am using an MDI form in which I have given option tool strip menu item as a call to a new child form. On the child form I have some buttons and DataGridView. But when I click the child form option the buttons and DataGridView are not displaying correctly. Provided I have already set the isMdiContainer property to true of MDI form.
The scenario runs successfully when I simply show a form, but the problem occurs when I use the form as a child form. Here is the code which I wrote in a tool strip menu item click:
frm_bank_master myfrm = new frm_bank_master();
myfrm.MdiParent =this;
myfrm.Show();

MDI Parent Child

I have created one MDI form & Want to inherit a already made Child form. So what I have to do to access all controls on my MDI in that child form. (I dont want to create a new inherited form, I have already one)
Your question is rather unclear but it appears that you are asking how to show a form as an MDI child. I assume that you have already set IsMdiContainer to true for your main form.
In order to show an MDI child you need to set the MdiParent property for the child form. Like this:
ChildForm myChild = new ChildForm();
myChild.MdiParent = this;//this is the main form, the MDI parent
myChild.Show();

Categories