Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
example : project has three forms: Form1, Form2,Form3. I stand at form1 create 1 object of form2. form2 is created for that platform, can not close Form1 without closing form2. Question is there a way to disable or hide away temporarily Form1. If we use methods visible , then it's only minimized below the taskbar,much form we open more forms will bw piled, the form number as much as our activation. What should I do? I heard that if they do solve the MDI form, his only two ways: as MDI or simple form is always
Posted

Do not use many forms, it's the worst. Do not use MDI, this is highly discourages (even by Microsoft) and very inconvenient to everyone. Here is the simplest thing to use: Tabbed interface. Use the control System.Windows.Forms.TabControl. You can add any number of tabs to it, with Designer or during run-time. What you had in the content of each form put is a separate tab.

[EDIT1]
If you need a log in first, do the following. Create one more form for log in. In the very beginning show it in a modal form calling System.Windows.Forms.Form.ShowDialog. After successful log in, this form will be closed and never needed again. In case of failure to log in, exit application after the modal dialog is returned with System.Windows.Forms.Application.Exit. This will be the optimal solution.
[END EDIT1]

[EDIT2]
Consider again: you have two forms: 1) Log in form, 2) Multi-tab form.
When you run your entry point, run System.Windows.Forms.Application form with Multi-tab form, not with login form. It will make your Multi-tab form the main one. Variant #1: in your entry-point method, call System.Windows.Forms.Form.ShowDialog with the log-in form before Application.Run. If the log in is not successful, just exit, so Application.Run will be never called. Variant #2: Handle the event Shown of the main form to call System.Windows.Forms.Form.ShowDialog with the log-in form. If log in is successful, just continue; if not — call System.Windows.Forms.Application.Exit right withing the handler (it works). Quite simple.
[END EDIT2]

[EDIT3]
See my solution of collaboration between forms and the discussions:
How to copy all the items between listboxes in two forms[^].
[END EDIT3]

This is easy.

—SA
 
Share this answer
 
v5
Comments
Richard MacCutchan 2-May-11 7:10am    
A useful and sensible solution +5.
Sergey Alexandrovich Kryukov 2-May-11 7:20am    
Thank you, Richard.
--SA
SaoLamEmDau 2-May-11 7:21am    
i want to check log in first, then open another form for other functions. i don't think tab control suitable
Sergey Alexandrovich Kryukov 2-May-11 7:29am    
No at all! Please see my updated Solution, in [EDIT]..[END EDIT]; this will be much better use then your initial log in form.
--SA
SaoLamEmDau 2-May-11 7:35am    
i know how to make log in form, i means : create another form on the base of current form. in the case you log in success, you will create new form for choose transaction. the new form you will create where if not on the base of current form(log -in form).if you close the log in form you will create the choose-transaction form where, if not using mdi or create in its. because form2 is created for that platform, can not close Form1 without closing form2. Question is there a way to disable or hide away temporarily Form1. If we use methods visible , then it's only minimized below the taskbar,much form we open more forms will bw piled, the form number as much as our activation
Why do you need Form1? If you are just loading a specific form depending on your environment then do this in your start-up code, and run either Form2 or Form3 depending on your requirements.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-May-11 6:58am    
OP commented:

i'm working with win form project and have problems with it!
i have form1 for test the problems of log-in . if access successful form1(log in true), you will be sent to form 2(choose the transaction example).how do i create 1 object of form2 without create it on the base of form1? suggest me if you know
Sergey Alexandrovich Kryukov 2-May-11 7:04am    
I guess I know what to do in this case.

Please see my solution.
--SA
you don't understand my quest.
using tab control doesn't solve my problems. because i want openning log-in form at the beginning. then if user log in with the right user name and password you will be sent to the next form which introduce you what transaction you want? so you choose want and next ...
if you use tab control , you can access form2 without check the user name and password. i want to check first! i think tab control doesn't suitable.
Notes : win form project
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900