Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 19th, 2007, 02:12 AM
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tricky : Don't want to load MDI form first

Hello,

I have a scenario in winforms where I have to load my main form (MDI) and then load login screen. I want to load only login screen and user authenticates then load main form ( MDI ).

My program.cs has main funtion. It contains Application.Run command. If I pass my login form for application.run as parameter. I cannot close (this.close) the login form when user successfully authenticates as it closes my application form. To avoid this I load my main form first with Application.Run followed by Login form in load event of main form

How can I load only login form without loading main form.

Thanks,
Navdeep


  #2 (permalink)  
Old July 20th, 2007, 12:02 PM
Authorized User
 
Join Date: Sep 2004
Location: Edegem, Antwerpen, Belgium.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Here is a possible solution:
You need 2 forms:
- MainForm (IsMdiContainer = True)
- LogonForm (optionally: ControlBox = False; FormBorderStyle = FixedSingle; MaximizeBox = False)

In the LogonForm create a method that checks the validity of the credentials passed. If the credentials are good, set the DialogResult of the form to OK.

this.DialogResult = DialogResult.OK;

In the Program.cs set the following:
[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(fals e);

    LogonForm frm = new LogonForm();
    DialogResult result = frm.ShowDialog();

    if (result == DialogResult.OK)
        Application.Run(new MainForm());
}

This way, your logonform is first opened and only if the user entered valid credentials, the mainform (mdi) is opened.

Greetz,

Geert

http://geertverhoeven.blogspot.com
  #3 (permalink)  
Old July 20th, 2007, 01:04 PM
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Geertz,

Thanks, I will surely test this out.
It should work fine if I close login form.


Navdeep

  #4 (permalink)  
Old July 20th, 2007, 01:48 PM
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by GeertVerhoeven



this.DialogResult = DialogResult.OK;


    LogonForm frm = new LogonForm();
    DialogResult result = frm.ShowDialog();

I think I am missing something here.
I new the form. Login screen appear. user enters credentials. CLicks ok. validations are checked. How does "result" gets value from frm.ShowDialog(). If I close the login it never reaches
    DialogResult result = frm.ShowDialog();


Navdeep

  #5 (permalink)  
Old July 20th, 2007, 03:24 PM
Authorized User
 
Join Date: Sep 2004
Location: Edegem, Antwerpen, Belgium.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The form class contains a field named DialogResult with type DialogResult.

Since the instance of the LogonForm is still available after the form is closed, you can request the value of the field by doing:

LogonForm frm = new LogonForm();
DialogResult result = frm.DialogResult;

If you check the signature of the ShowDialog method, you can see that it returns a value with type DialogResult. This value is the value that comes from the forms DialogResult property.

If it isn't clear, please let me know.

Geert

http://geertverhoeven.blogspot.com
  #6 (permalink)  
Old July 20th, 2007, 09:46 PM
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Geert,

Thanks for your inputs.
I have tested the code. this is the main() code
Quote:
quote:
static void Main()
        {
            //string mys = "c:\abc";
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(fals e);
            frmLogin frm = new frmLogin();
            frm.ShowDialog();
            DialogResult result = frm.DialogResult;
            if (result == DialogResult.OK)
            {
                Application.Run(new frmMain());
            }

        }
"result" is always "cancel". I am using this.close after I check credentials on logon form. So the logic does not work. Can you test at your end. Am I missing something. I understand what you have tried to convey but showdialog returns cancel.

-Navdeep


  #7 (permalink)  
Old July 20th, 2007, 09:53 PM
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by GeertVerhoeven


If you check the signature of the ShowDialog method, you can see that it returns a value with type DialogResult. This value is the value that comes from the forms DialogResult property.
I got the missing link.
Apart from last code I mentioned in last post , I added this line of code in logon form Ok button after successful authentication

Quote:
quote:
this.DialogResult = DialogResult.OK;
It works now.
Thanks.



  #8 (permalink)  
Old May 6th, 2008, 01:51 AM
Registered User
 
Join Date: May 2008
Location: chennai, tamilnadu, India.
Posts: 8
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to samdoss Send a message via Yahoo to samdoss
Default

Program.cs LoginForm and MainForm

The Code is Perfectly Working.

frmlogin.cs file

btnok_click()
{
this.DialogResult = DialogResult.OK;

}

program.cs file

static void main()
{

Application.--------;
Application.---------;
frmLogin login = new frmLogin();
DialogResult result = login.ShowDialog();
if (result == DialogResult.OK)
Application.Run(new MainForm());

}


Regards,

Samdoss.J:(

samdoss.j
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying MDI Child Form Menus with MDI Parent ashu_from_india Pro VB 6 3 June 10th, 2008 11:01 PM
Controlling MDI child form from MDI parent panel LuxCoder Pro Visual Basic 2005 1 May 25th, 2007 12:20 PM
Controlling MDI child form from MDI parent panel LuxCoder VB.NET 2002/2003 Basics 7 April 11th, 2007 02:38 PM
Controlling MDI child form from MDI parent panel LuxCoder VB How-To 1 April 9th, 2007 03:25 PM
Controlling MDI child form from MDI parent panel LuxCoder Visual Basic 2005 Basics 2 April 9th, 2007 03:24 PM



All times are GMT -4. The time now is 05:09 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.