Click here to Skip to main content
15,918,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ellooo People,
I have a school project that i have to make in Visual Studie 2013 Proffesional and i dont know what to do now...
My project/Problem:
I need to make a form where i can log in and
then get to a main menu where the text ( the line in the top ) can be found
I have tried everything but the program says that the name cannot be found in the directory
I'm already to the point where when i click login i go to the main menu (Another form)

For more information please ask me

greets

Mike
Posted
Comments
BillWoodruff 30-Jan-14 1:56am    
See if this is useful:

http://www.codeproject.com/Answers/718055/call-private-method-from-another-form

It's not to difficult: but exactly how you do this depends on how you handle the login on the first place.

Personally, I would bring the main form up first, and open the login form in the Load event:
frmLogin log = new frmLogin();
if (log.ShowDialog() != DialogResult.OK)
   {
   Close();
   }
You then do all the validation in the login form and exit with OK or Cancel depending on if the logon works or not - if it doesn't, then the code above closes the application.

All you then have to do is add a property to the login form which returns the login user name, and access it in the main firm code:
Text = "User : " + log.UserName;
 
Share this answer
 
can you show us your code snippets?
OriginalGriff was right,using property to the log in form ur If you want create a class for property that will hold the value you want to pass

C#
Public Class MyClass
{
public string myValue{get;set;}

}


Log in form:
C#
If (textBox1.text==password and textBox2.Text==UserAccount)
{
  var cls=new myClass;//instantiate the class
  cls.myValue=textBox2.Text;//pass the value
  MainForm.ShowDialog();
}


then in Main form
C#
var cls=new myClass;
textBox3.Text=cls.myValue;
 
Share this answer
 
Hi there. when you are deciding for creating a application consider followings:
1-what data you need?
2-create a class that has your requested data:
In a class you can define property for working with that class such as this:
C#
class Person
{
    public string UserName { get; set; }
    public string Password { get; set; }

    private Person()
    {
        Validate();
    }
    public Person()
    {

    }

    private void Validate()
    {
        //Here you must connect to some dataSource such as SQL server for correction of entry data
    }
}


3-now you must design your UI(form).
4- I suppose you create a form that has two TextBoxes and two Button. In LogButton_Click:
C#
public Form1()
{
    InitializeComponent();
}

private void LogInButton_Click(object sender, EventArgs e)
{
    Person person = new Person();
    person.UserName = UsernameTextBox.Text;
    person.Password = PasswordTextBox.Text;
}
 
Share this answer
 
Thanks alot griff but,
I dont know what to fill in where or what to keep as it is
like .. what becomes log or frmlogin or log.username

I used textboxes to enter the username and password there only a password check who checks if the value is equal with the right password so the username is just for fun
 
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