parent form is accessible when child form is open - c#

I have created a parent form and a child form in c# when i click a menu item in parent form, it opens the child form but still i access the parent form.i want that the parent form will remain inaccesible until the child form is open.please send me the code.thnks

try with this
form.ShowDialog()

Probably you should use form.ShowDialog() method instead of form.Show()
Definitely you should add a better description, at least framework you are using (WinForms?). C# is not a framework.

Use, form.Hide() process to make the Parent form to be not accessable when ever the child form opens and again give form.show() to activate the parent form.

If you want your parent form visible while showing your child form then you can do following.
form.ShowDialog(this).
Where this is the instance of your parent form.
On the other hand, if you want your parent form hide while showing child form you can do following
this.Hide();
form.ShowDialog(this)

Related

How to detect that a modal form is opened from a child form? (C# & VS2017)

Maybe it's a silly question but I can't find a solution.
I have an MDI form with multiple children. There is one that I could say is the main one.
To detect that the principal is no longer used and another child form is used I use the 'Leave' event which works very well.
The problem is when from the mdi form, a modal type (.ShowDialog ()) is executed, the Leave event doesn't happen in the child form.
Any suggestion or comment on how to get it is welcome.
you can use this
to just use the current class which is in your situation the (main) .
I solved it this way:
From the MDI form, from where the modal forms are called, I search for the child forms and if it is the "main" one, I call a public function that does the same as the Leave event of the "main" form:
foreach (Form childform in this.MdiChildren)
{
if (childform.Name.Equals("MyMainForm"))
{
var formMain = (MyMainForm)childform;
formMain.stopTimer();
}
}
It may be a cumbersome solution, but it is functional.

WinForms MDI form smooth switch between child forms

I have a MDI parent form
formMain
I use the form to display 2 different child forms inside it.
formChildOne, formChildTwo
The problem is that whenever I switch between the child forms, the interface gets really jittery until the form is fully shown and it looks ugly as hell.
How can I make the process look a little more elegant?
Try to set this property on your Child forms and parent form:
DoubleBuffered=True
Hope it helps!

Whats the difference between Parentform and Owner

In winforms we have objForm.Owner and objForm.Parent. Whats the difference between these two.
I opened a form B from form A as a dialog and was expecting to access form A's public properties from form B using ParentForm property but finally ended up using Owner property instead as ParentForm was null !!
A parent-child relationship exists between windows when the child is embedded in the parent window and cannot move outside of its bounds. Examples are child controls like TextBox and Panel. And the MDI windowing model, MDI child windows are embedded in the MDI parent and parented to the dark-gray MDI client window.
An owned window applies to top-level windows and primarily controls their Z-order. An owned window is always on top of its owner. It is also minimized and restored along with its owner. Examples are tool windows and dialogs.
Note how a Form is normally a top-level window and does not have a parent. So wouldn't have a use for its Parent and ParentForm properties. It can however be turned into a child window by setting its TopLevel property to false. Sample code is here.
Form.Owner - Is the Form that "owns" this form. For example Find/Replace dialog would be Owned by Notepad's main window. If you
minimize the main Form, the owned form will minimize, if you restore
the main form, the owned form will restore
ContainerControl.ParentForm - Is the Form that this ContainerControl is ultimately placed on
Check this article. Their is explained Parent too.

Passing data from MDI Child to MDI Parent

I new some help to pass data from my mdi child to the mdi parent.
And I want to show the string (on the mdi parent) that I wrote in the mdi child.
I also have to make the string appear after close the mdi child.
Any help?
From the parent form you can access the parent form my name
Form frm = (Form)Application.OpenForms["ParentFormName"];
Just declare a variable in parent with internal access and assign values of child form to that variable. You should be good to use the value on parent form.

How do a make one form stay on top of another?

I have found the Form.TopMost property but it puts the form on top of everything, including stuff that isn't part of my app. I've got a suspicion that I'm missing something obvious here. (Is Form the proper bases class for a non modal dialog box?)
Use the Form.Owner property of your dialog form and set it to the main Form.
Read more here
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner.aspx
The Owned form will never be displayed behind the Owner Form.
It is very simple; You just have to pass the owner when you call the Show() method
YourForm.Show(parentForm);
You can specify parent-child relationships between windows by supplying the parent Form as parameter to the ShowDialog() method called on the child Form. The child window will then stay on top of the parent and also minimize and restore along with the parent.
If i understand you correctly your opening a form from your application, and you want your new form to be on top of the old one.
To do this you can use ShowDialog() and StartPosition
SomeForm MyNewForm = new SomeForm();
MyNewForm.ShowDialog();
this will make that form stay on top of the orignal one, and you can also use
MyNewForm .StartPosition = FormStartPosition.CenterParent;
To control where that new form shows on the screen.

Categories

Resources