i have a program where i have a little loginScreen form and a mailer form and when you type in your email username it sets it to a variable of type string as well as the email password on the login form what i want to do is be able to access the variables that it just set on the mailer form. how would i go about that?
i have tried making everything public, but i am a noob haha.. when i tried to use these variables it wont let me. i have tried initiating these variables in the static void main method of the program but i cant access them that way either :S
4 replies to this topic
#1
Posted 18 August 2010 - 09:07 PM
|
|
|
#2
Posted 18 August 2010 - 09:30 PM
oh... let me welcome myself to the world of public string.. lol
now i can use those variables but for some reason when i go to use it on the second form the variables dont take their assigned value from the login form. they get reset to nothing i think its because when i create a new instance of the login screen it redefines my variables as nothing again.. here is the code for the login form
now i can use those variables but for some reason when i go to use it on the second form the variables dont take their assigned value from the login form. they get reset to nothing i think its because when i create a new instance of the login screen it redefines my variables as nothing again.. here is the code for the login form
namespace WindowsFormsApplication1
{
public partial class loginScreen : Form
{
public string eUsername = "";
public string ePassword = "";
public loginScreen()
{
InitializeComponent();
}
public void logIn_Click(object sender, EventArgs e)
{
mailer mailer = new mailer();
mailer.Show();
eUsername = eUsernametxt.Text;
ePassword = ePasswordtxt.Text;
this.Hide();
}
}
}
and here is the mailer formnamespace WindowsFormsApplication1
{
public partial class mailer : Form
{
string eAddress = "";
string eSubject = "";
string eBody = "";
public mailer()
{
InitializeComponent();
}
public void eSend_Click(object sender, EventArgs e)
{
// getAddress();
// getSubject();
// getBody();
// getAttach();
eAddress = eAddresstxt.Text;
eSubject = eSubjecttxt.Text;
eBody = eBodytxt.Text;
loginScreen login = new loginScreen();
MailMessage mailmessage = new MailMessage();
SmtpClient mailservice = new SmtpClient("smtp.gmail.com");
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(login.eUsername,login.ePassword);
mailservice.Port = 587;
mailservice.UseDefaultCredentials = false;
mailservice.Credentials = nc;
mailservice.EnableSsl = true;
mailmessage.To.Add(eAddress);
mailmessage.Subject = eSubject;
mailmessage.Body = eBody;
mailmessage.From = new MailAddress("proxsi@gmail.com");
mailservice.Send(mailmessage);
}
}
}
im not really sure how to get around this. any ideas?
---------------------------------------------------------------------------------------------------------------------
I make everything more complicated than it needs to be..
I make everything more complicated than it needs to be..
#3
Posted 19 August 2010 - 12:11 AM
Pass the variables to the constructor. Or use set methods.
in mailer class:
mailer mailer = new mailer( eAddresstxt.Text, ePasswordtxt.Text );
in mailer class:
string eAddress = "";
string pass = "";
public mailer(string eAddr, string pass)
{
eAddress = eAddr;
password = pass;
InitializeComponent();
}
#4
Posted 19 August 2010 - 09:51 PM
hmm im not quite getting it, does anyone have a link that explains constructors? i would rather learn how to use them completely and properly. i have found a bunch of links but they are quite hard to follow : /
---------------------------------------------------------------------------------------------------------------------
I make everything more complicated than it needs to be..
I make everything more complicated than it needs to be..
#5
Posted 20 August 2010 - 03:12 AM
Googling (c#) constructors gives plenty of information.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









