Register for your free account! | Forgot your password?

You last visited: Today at 16:36

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Help in c#

Discussion on Help in c# within the .NET Languages forum part of the Coders Den category.

Reply
 
Old 07/08/2012, 20:29   #16
 
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
Using a constructor is strange to you? :<
MoepMeep is offline  
Old 07/08/2012, 20:29   #17
 
badguy4you's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 477
Received Thanks: 178
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 ?
badguy4you is offline  
Old 07/08/2012, 20:33   #18
 
Coding Lounge's Avatar
 
elite*gold: 0
Join Date: Mar 2011
Posts: 806
Received Thanks: 160
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....
Coding Lounge is offline  
Old 07/08/2012, 20:34   #19
 
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
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.
MoepMeep is offline  
Old 07/08/2012, 20:39   #20
 
badguy4you's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 477
Received Thanks: 178
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;
badguy4you is offline  
Old 07/08/2012, 20:41   #21
 
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
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);
MoepMeep is offline  
Old 07/08/2012, 20:45   #22
 
badguy4you's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 477
Received Thanks: 178
lol i made it 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 )
badguy4you is offline  
Reply




All times are GMT +2. The time now is 16:37.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.