hi everybody,

i need help with windows form, i am working in one win application, so what i need, ex. i have form which is name MainForm, and i have another form which is for user login named Loginform, what i need is when i execute a project i need that login page form to be showed up first and after the user is loged in, than to show up the Main form.

any help will be appreciated

Change start up from property of application set your login form instead of Main Form. after this make object of main form in login page and show that form.If you want to send anything from login page to main form make parameter for that and pass them.

static void main()
{
LoginForm login= new LoginForm();
if(login.ShowDialog() == DialogResult.OK)
{
Application.Run(new Form1(login.User, login.Pass));
}
}
public partial class Form1:Form
{
string _User,_Pass;
public Form1(string user, string pass)
{
_User = user;
_Pass = pass;
}
}

To get the login form to show first go to Program.cs in your solution and change the Application.Run(new youformname); to be Application.Run(new Loginfor);

to show the menu, in the method that checks the login details do

MainForm mainFrm = new MainFor(); 
this.Hide();
mainFrm.Show();

Simpliest way to do so, it touse ShowDialog method:

//in the main form:
using(Login log = new Login())
{
     if(log.ShowDialog() == DialogResult.OK)
     {
          Application.Run(Form1);
     }
}

//in login form:
//when you do all the checking on the user`s name and password 
//and all is OK, do:
this.DialogResult = DialogResult.OK;

Thanks everybody, i solve the problem earlier, but thanks anyway

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.