Help in c#

07/08/2012 20:29 MoepMeep#16
Using a constructor is strange to you? :<
07/08/2012 20:29 badguy4you#17
the problem is that when i call OptimumMain = new OptimumMain(); is that i make a new instance of it so i get empty fields idk what i really do is there an easy way to make the whole project as 1 class ?
07/08/2012 20:33 Coding Lounge#18
Code:
//OptimumMain om = new OptimumMain();
           string username = OptimumMain.txtWebUser.Text;
           string password = OptimumMain.txtWebPass.Text;
And you have to declare 'username' and 'password' as a

Code:
public static username;
public static password;
And Again....
07/08/2012 20:34 MoepMeep#19
There is no need to create a new instance of OptimumMain. When you press your button, create a new instance of the iWebWrap class and pass id/pw.

@Coding Lounge thats not a good way to do it.
07/08/2012 20:39 badguy4you#20
U mean that in the Login Class i make
Code:
Public string username;
Public string password;
and in the button i make that
Code:
            iWebWrap ir = new iWebWrap();//iWebWrap is the login class
            ir.username = txtWebUser.Text;
            ir.password = txtWebPass.Text;
07/08/2012 20:41 MoepMeep#21
This would work but isnt recommended. Attributes should be private. Use the constructor to pass id/pw ;)
Code:
iWebWrap ir = new iWebWrap(txtWebUser.Text, txtWebPass.Text);
07/08/2012 20:45 badguy4you#22
lol i made it :D but i will try your recommended solution now and tell you what i did

Here is the solution [NOTE : dont need to change modifiers to Public just keep it Private]



In the iWebWrap (the login check class)

Code:
        public string username;
        public string password;

        public void login()
        {
            if (username == "admin" && password == "admin")
            {
                MessageBox.Show("Worked !");
            }
            else
            {
                MessageBox.Show("Wrong ID or PW");
            }
        }
In the OptimumMain (Which is the main GUI class)

when login button clicked
Code:
            iWebWrap ir = new iWebWrap();
            ir.username = txtWebUser.Text;
            ir.password = txtWebPass.Text;
            ir.login();
MoepMeep tell me what is your openion about what i did [note i did not changed the modifier its private as it is]

Also there is a small question that not relevant to programming when i am designing the UI i some times want to hide something (not from the real program but from preview in visual studio so i can add somethings behind it without moving )