Help in c#

07/08/2012 05:44 badguy4you#1
i want to read txtbox1.text from another class so i made this

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Mains;

    public class iWebWrap
    {
        public void login()
        {
           OptimumMain om = new OptimumMain();
           string username = om.txtWebUser.Text;
           string password = om.txtWebPass.Text;


           MessageBox.Show(username);
           MessageBox.Show(password);
        }
    }
and changed the txtboxes modfiers to public but the problem is

even there is text in the textboxes the messagebox shows them empty
(idk what is the problem now)

UPDATE : HERE IS WHAT I WANT TO DO EXACTLY

What i really want to do is as the following

i have Form1 that has 2 textboxes and a button

and have login.cs which is the class that will handle the login process

so what i want to do is transfer the 2 textboxes values to the login class so the login class can determine whether the login info are correct or not
07/08/2012 14:23 MoepMeep#2
You made a new Object of the OptimumMain class, ofcoz they are empty ;)
For this to work your OptimumMain class must be static, but well, thats not the way you should go. Pass ID and PW in your constructor for the IWebWrap class. If this is not possible for some reason, use a static data class or fire an event whenever txtWebUser
or txtWebPass text changes.

A textbox is private for a reason, you should not change it. Create a method to read it.
Code:
public string getID() {
      return txtWebUser.text;
}
07/08/2012 17:25 badguy4you#3
mmm i tried the way you told but still empty :D can you be a little more clear
07/08/2012 17:41 MoepMeep#4
Code:
public iWebWrap(string id, string pw) {
   this.id = id;
   this.pw = pw;
}

//And in your MainOptimum-Class
iWebWrap web = new iWebWrap("id","pw");
You should read some more about OOP.
07/08/2012 19:10 badguy4you#5
so there is no way to make the whole project as 1 thing so i can call any textbox any button any string from anywhere of the whole project ?

What i really want to do is as the following

i have Form1 that has 2 textboxes and a button

and have login.cs which is the class that will handle the login process

so what i want to do is transfer the 2 textboxes values to the login class so the login class can determine whether the login info are correct or not
07/08/2012 20:00 MoepMeep#6
Quote:
Originally Posted by badguy4you View Post
so there is no way to make the whole project as 1 thing so i can call any textbox any button any string from anywhere of the whole project ?

What i really want to do is as the following

i have Form1 that has 2 textboxes and a button

and have login.cs which is the class that will handle the login process

so what i want to do is transfer the 2 textboxes values to the login class so the login class can determine whether the login info are correct or not
Did you actually read my answer?
07/08/2012 20:07 badguy4you#7
man this.id is not declared ! what is that
what i do with id=id and what then when i called this with my login button click
iWebWrap web = new iWebWrap("id", "pw");

and i am not that bad with c# that i have to learn it :D but this thing just annoying
07/08/2012 20:09 MoepMeep#8
Quote:
Originally Posted by badguy4you View Post
man this.id is not declared ! what is that
nc.

Quote:
and i am not that bad with c# that i have to learn it :D but this thing just annoying
You know nothing about programming at all, start learning or quit.
07/08/2012 20:10 Coding Lounge#9
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;
07/08/2012 20:11 badguy4you#10
MoepMeep Okey just stop posting here if you are insisting on that i dont wanna help from you if so
07/08/2012 20:12 MoepMeep#11
Quote:
Originally Posted by Coding Lounge View Post
Code:
[COLOR="Red"]OptimumMain om = new OptimumMain(); - DELETE[/COLOR]
           string username = OptimumMain.txtWebUser.Text;
           string password = OptimumMain.txtWebPass.Text;
This will just work if the whole class is static ;)
07/08/2012 20:16 Coding Lounge#12
And you have to declare 'username' and 'password' as a

Code:
public static username;
public static password;
07/08/2012 20:24 badguy4you#13
Quote:
Originally Posted by MoepMeep View Post
This will just work if the whole class is static ;)
Which whole class you mean ?

this

static class iWebWrap
{
string username = OptimumMain.txtWebUser.Text;
string password = OptimumMain.txtWebPass.Text;
}

still tells me An object reference is required for non static field ?
07/08/2012 20:26 MoepMeep#14
The OptimumMain class would have to be static, but as I told you, don't do it.
07/08/2012 20:27 badguy4you#15
... so what i do the code u provided is strange to me