6
Answers

Simple Form Problem(hopefully)

mark esco

mark esco

14y
11.7k
1
I am brand new to C# and am having problems. I need my Main form to open my FileDialog
form. I need the file dialog box to stay on top of my Main form(Preferably not on top of other
applications forms, but i can live with out this). I need the FileDialog form to be a child ( not MDI)
of the first form (a modal, I believe it is called). I tried Google, Microsoft, various others, and
I know it's something simple I am overlooking.

Here is my code. I have 2 designed forms frmMain and frmFileImport.

 frmFileImport FileDialog = new frmFileImport();
 frmMain MainForm = new frmMain();
 FileDialog.TopMost = true; 
 FileDialog.ShowDialog(MainForm);

The new form gets created (automatically minimized for some reason) and is just like any
plain form. I can keep clicking my Main form button(the one that opens the FileDialog) and
new FileDialofg window will appear. I only want one FileDialog and have my Main form locked
until FialDialog closes!

I am using Visual C# Express 2010. I think in VB its just frmName.Show(OwnerName).
Answers (6)
0
mark esco

mark esco

NA 12 0 14y

Thanks Sam. I thought I had it working beacuse my dialog was no longer minimized. The actual code I use now is
Form1 frm1 = new Form1();
Form2 frm2 = new Form2();

frm2.ShowDialog(frm1);
Thanks again everyone =)

0
Sam Hobbs

Sam Hobbs

NA 28.7k 1.3m 14y
Note that Show will show the form modeless. If you want modal then use ShowDialog. Modeless means that both the form shown and the form that shows can be used. Modal means that the form that is shown must be closed before the showing form can be used again.
0
mark esco

mark esco

NA 12 0 14y
I got it working!

I started a new project
Named everything the same
and used the same code......This time it worked!

I probably messed up a naming reference deep in the project or something.
Thank you for all your help.

And if there are any newbies(like me) here is the syntax i used to show a form
as a dialog controlled by another form.

Form1 frm1 = new Form1();
Form2 frm2 = new Form2();

frm2.Show(frm1);

Place above code in a button (or some other control)
Thanks again everyone. =)

0
Sam Hobbs

Sam Hobbs

NA 28.7k 1.3m 14y

I don't know what your frmFileImport class is but you probably want to use the OpenFileDialog class instead. There are many samples of using it. The OpenFileDialog.Show method will show the dialog modal the way you need to. You probably need to use the OpenFileDialog in your main form; add a handler for the form load event to your main form and show the OpenFileDialog there.
0
mark esco

mark esco

NA 12 0 14y

Thanks for the reply. Unfortunatly I have checked windowstate. That's kind of what concerns me too. I feel it must be a property of one of the forms. I can set the windowstate to any value, even maximized and it always loads in minimized state. I think it does this because it creates a new instance of the form and maybe wipes out some properties. I have programmed in VB for years and I guess I dont understand why you have to create a new instance of a form you have already designed. I will research that on my own(i realy like C# too), but for now I'm going to try to get this owner window thing working. Thanks again for your help
0
Shankey

Shankey

NA 2.7k 624.6k 14y
hi mark,

I created the application with your code, its working fine, but if your filedialog page getting minimized, then plz check the windowstate property of the filedialog form and change it to normal

please do let me know what you have done to solve your problem