C# Help on accessing a textbox's text from another form and panel
in case if you didnt get point, there's an email textbox and i want to save the email adress and use it on another form in different panel but it doesnt save the email at the variable that i created for the email
12 Replies
assuming you are using winforms based on "textbox" and you have 2 forms...Form A where the text is entered, Form B where the text is to be used.
you can pass the string from formA to formB via the constructor of formB
it automatically deletes the data that i saved on the variable when i pass to another form and couldnt find a solution yet
already doin' this
show your code then
sure give me a sec please
class uyeGiris
{
public Boolean x = false;
public string kayitTut { get; set; }
public void girisYap(string Eposta, string kullaniciSifre)
{
destekpaneli dp = new destekpaneli();
frmWebPanel web = new frmWebPanel();
string conn = "Data Source=NICHT;Initial Catalog=otomasyon;Integrated Security=True";
SqlConnection connection = new SqlConnection(conn);
string stri = "SELECT * FROM kullGiris WHERE Eposta=@eposta AND Sifre=@sifre";
SqlCommand command = new SqlCommand(stri, connection);
command.Parameters.AddWithValue("@eposta", Eposta);
command.Parameters.AddWithValue("@sifre", kullaniciSifre);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
kayitTut = Eposta;
// Kullanıcı adı ve şifre doğru
MessageBox.Show("Giriş başarılı!");
web.Show();
x = true;
}
else
{
// Kullanıcı adı veya şifre yanlış
MessageBox.Show("Kullanıcı adı veya şifre yanlış!");
}
reader.Close();
connection.Close();
}
}
---------------------------------------------------------------
you can pass the string from formA to formB via the constructor of formBwhere do you do this ^
well actually i deleted the codes after it didnt work, may you tell me how to use the constructor
like how it should be like
where do you instantiate and show the second form?
that's where i should set and save the variable i guess
actually he just wanna use kayitTut variable on destekpaneli's any textbox
yes i gotta use the kayitTut's value on another textbox and the textbox located in different panel and form
ok, i'm still not sure what i'm looking for in your code
but taking the above method as an example.... if you are moving from
frmUyeGiris
to frmMain
you can pass data to frmMain
like
1️⃣
that would require you to have a constructor in frmMain
that looks like
or... if you don't want to change the constructor, you can do
2️⃣
and to pass the data you'd do