My main form is this
Now my problem occurs when I click Add -> Student, which is meant to bring up a new window that, instead it does this
So as you can see it opens the new form inside the same window. It didn't use to do this, then I made the main form an MdiContainer and set it as the MdiParent of the second form.
Is there a property I can change to make this new form pop up in a new window? Becuase I need to leave the MdiContainer property as True so that I can take data from Form2 and use it in Form1
Please let me know any other information you may need to help me fix this issue, as I'm not sure what caused it so I don't know what to change in order to fix it or even where I'm meant to be looking
you need to hide form enroll
when you open add window add.show()
you need to hide enroll form enroll.hide()
Related
I'm trying to make a WindowsFormApplication in Visual Studio 2015 and need some help.
I've been trying to search for the answer on internet but can find out how to do the following:
I have two windows (solutions?). I open the second window with a button in the first one with this code:
this.Hide();
intermec prodinter = new intermec();
prodinter.ShowDialog();
My question is:
How can i "include" the second window (like "include" in PHP) instead of close the first window and then open the next one, like it does now?
A Form is just another Control. Think of it as a Container (because it holds other Controls).
A User Control can also hold more than one Control. There are ways you can display a Window inside another Window in a WinForms app, but the desired effect is not always guaranteed. So it would be best to place all of your controls (for "page 1", for example) in a User Control called "Page1", and then, when appropriate, add that User Control to the Form, and set its Dock property to Fill.
And when it's time to show a different "page", Hide(); "Page1", and Show(); "Page2".
I think you are talking about form inheritance:
Just create a form, lets call it as frmBase. And add some controls onto frmBase which you want to have on other forms as well.
Create other form, lets call it as frmDerived.
In the code behind of frmDerived, just do the following:
// derive the frmDerived form from frmBase
public partial class frmDerived : frmBase
{
public frmDerived()
{
InitializeComponent();
}
}
And then just check the frmDerived form design, it should include everything from frmBase.
And you may want to make the access modifier of some controls of frmBase to Public as required to access them on frmDerived.
I hope this will help you. :)
I want a form to be shown modal every time it is opend. Since I can not change the way it is created and opend. I wondered if it is possible to make the form stay on top from within the forms class.
One opportunity is the TopMost property. This works in general, but if I display the form while the main thread is waiting for it to close, the form will stay on top even if I change the application(to a browser for example). So no matter where I am, the form is still displayed.
Another issue which I came across is that in some cases it is adopted by the parent form which then might block other windows or popup messages.
I was thinking about a hook to the OnLostFocus event to get it on top again, once the focus is lost, but I'm not sure if that is a good idea ...
Any helpful thoughts about it?
Edit
Due to the comments I will extend my description, Here is the real use-case
We are using the Devexpress's SplashScreenManager which is able to show a certain form as a WaitForm. Since the WaitForm is not intended to be shown modal(see on the Support Center), we are looking for a way to do so.
We can not change the way the form is shown, because this is done through the SplashScreenManager. The WaitForm is shown both from the main thread, as well as from certain backgroundworker.
So this is only about an own form of ourselfs, displaying it within our own application.
Use:
TopLevel = true;
This will do exactly what you want; be topmost as long as the main form is shown and hide if the mainform is hidden by another window.
You can set the owner of your splash form to your main form explicitly without using .Show(owner).
splashForm.Owner=mainForm;
splashManager.Show(splashForm);
We did not want the TopMost property since it works on windows level and covers other windows too (for example the browser).
In the end I hooked up on the focus event of the window to make sure the window is always on top.
I am writing a Settings form for one of my applications. Once the user clicks Tool > Settings a new form comes up with the settings that can be changed.
The TopMost property is set the True and working properly.
What I can't seem to find how to do is to keep the Form on focus. I do not want the use to be able to leave the form. The user has to close the form to continue using the application.
Thank you...
You are probably using Show() to show the settings form. Instead, use ShowDialog().
http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx
Display it like this:
FormChild1 Child = new FormChild1();
Child.ShowDialog(this);
I want to make an application that have one main form that have one functionality = Add new form.
I dont know how forms will be created, they are created dynamically by the user (AddForm methos from the main form).
All the subs forms are the same but some of thier prop receive differnce parameters (it can be in the ctor or later).
I want to be able to close all the forms when I close the main form.
Before new form will displayed I want to display setting form (to take the form parameters) maybe with ShowDialog method and do validating check on the form and just if the form validate the new form will displayed, if not (or if the user prees cancel) the form will disposed.
I know aboout MDI but I really perfer other way
Any ideas?
Thanks!
Closing all forms when main form is closed is somewhat easy, you just pass the main form reference in Show() method of the "child" forms; e.g. if you show child from main, you do:
child.Show(this);
This needs to be done if the your main form is not the real "main form of the program", but you want to close all "child" forms.
However, wiring all this together would preferably be done in some special class for this purpose, maybe called ScreenRepository. In this class, you would have a collection of open forms at any moment, you would deffer form creation to this class (so that this class automatically injects form parent) etc... Having this class would be easy to re-activate (give focus) the form if it is behind other forms, create new form if needed etc...
Idea is simple create a application that open a main form a the beginning and then open open other forms if needed if you close main form rest of forms are also closed. Like in GIMP.
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.