FOXBAT
asked on
VERY Easy C# Question
Hello, i just began playing with C#. I’m used to console C/C++ programming. I am simply wondering how I can pass a text string from one .cs form to another.cs
I have a typical login window, which consists of some textboxes, labels and buttons.
On click I want the event handler to pass the user name and password to a function in a different .cs file that is part of the project, one that holds the authenticate function logic.
I want to do something like this
Form1.cs
...
private void OK_Click(object sender, System.EventArgs e)
{
authenticate(UserName.Text , Password.Text);
}
...
-------------------------- -
Authenticate.cs
...
authenticate(string username, string password)
{
if( username == ...etc etc )
return etc;
}
...
Could some one please explain and show with a basic example how I could pass the text string.
Thanks in advance! =)
I have a typical login window, which consists of some textboxes, labels and buttons.
On click I want the event handler to pass the user name and password to a function in a different .cs file that is part of the project, one that holds the authenticate function logic.
I want to do something like this
Form1.cs
...
private void OK_Click(object sender, System.EventArgs e)
{
authenticate(UserName.Text
}
...
--------------------------
Authenticate.cs
...
authenticate(string username, string password)
{
if( username == ...etc etc )
return etc;
}
...
Could some one please explain and show with a basic example how I could pass the text string.
Thanks in advance! =)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i read a book and got the right syntax
Class1 obj = new Class1();
if(obj.Check(UserName.Text ))...
Class1 obj = new Class1();
if(obj.Check(UserName.Text
you need to either declare an instance of the class or make it static. I see you know how to declare the instance, and the example below is for static.
public static class class1
{
public static int Check(string uname)
{
if(uname == "aa")
return 1;
else
return 0;
}
}
now in your ok_click you can do this
int Valid = Class1.Check(UserName.Text );
public static class class1
{
public static int Check(string uname)
{
if(uname == "aa")
return 1;
else
return 0;
}
}
now in your ok_click you can do this
int Valid = Class1.Check(UserName.Text
ASKER
i tried something like this but it didnt work, how can i state the retrun type, or in other words how do i get it to work?
Form1.cs
...
private void OK_Click(object sender, System.EventArgs e)
{
Class1 = new Class1(UserName.Text); }
...
------------------------
Class1.cs
...
public class Class1
{ public int Check(string uname)
{
if(uname == "aa")
return 1;
else
return 0;
}
}