CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2006
    Posts
    645

    Showing a dialog from a dialog....

    Hi all,
    I am developing a winforms application. There is a login functionality requirement. So I have created a multi-tabbed login dialog, which has login, register, forgot password, etc tabs. I have included 2 buttons on the dialog outside of the tab control, to perform the dialog result accept and reject functionality. On accept dialog however, want to open up the applications main form. So I am having the following problems:
    - First and the most important issue is the simplest thing a .NET guy could do...as I said pop up another dialog / form from a button click event on another dialog / form. In our case, I wrote the following code:
    Code:
    // The following is the part of code where a successful login brings up the main form.... 
    public void btnAccept_Click(System.Object sender, System.EventArgs e)
    {
        // ...if user is valid user
        MainFrm mfrm = new MainFrm();
        mfrm.Show();
        // However, a new form shows up, but is blank, wthiout any control and closes instantly
        // I also tried declaring a class level instance of MainFrm, but no difference
    }
    Coming from VC++ background and even after knowing .NET well, I am not able to figure out this. Also, I want to transfer the applications control to the Mainform and close the login dialog as its use is over...This is the urgent part...can anyone help?
    - I have never created a windows application which is secured and requires a user to login. Is there a good example on web that would allow me look into more standard way to deal with this kind of application as in the case of plentiful examples on web for ASP.NET applications?
    - I just want to encrypt the user name and password and store them in a text file and then retrieve them after decrypting them for matching them to the user entered details. Is there an example shows how to encrypt the login info and stores it in text file?
    Thanks,
    Bhushan

  2. #2
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Showing a dialog from a dialog....

    you could just show the login form in your Program.cs file then when the login succeeds instantiate the MainForm.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  3. #3
    Join Date
    Jun 2006
    Posts
    645

    Re: Showing a dialog from a dialog....

    You mean to say Application class main? Shall I be handling something like:
    if(dialogresult == DialogResult.Ok)
    {

    }
    in the application main? I had thought about that but just could not justify myself...please let me know,
    Thanks,
    Bhushan

  4. #4
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Showing a dialog from a dialog....

    I mean something like this:

    Program.cs
    Code:
    namespace WinFormsTests
    {
    
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
    
                LoginForm frmLogin = new LoginForm();
                frmLogin.ShowDialog();
                if (frmLogin.LoggedIn == true)            
                    Application.Run(new MainForm());
            }
        }
    }
    LoginForm.cs
    Code:
    namespace WinFormsTests
    {
        public partial class LoginForm : Form
        {
            private bool loggedIn = false;
    
            public bool LoggedIn
            {
                get { return loggedIn; }
                private set { loggedIn = value; }
            }
    
            public LoginForm()
            {
                InitializeComponent();
            }
    
            private void btnLogin_Click(object sender, EventArgs e)
            {
                this.LoggedIn = true;
                this.Close();
            }
    
        }
    }
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured