|
Hi Guys. I have tried a few dirrent ways of doing this but none of them seem to work for me. I am trying to get the "username" copied from my logon form into the Main form.
The logon form is called from the mainform. user enters username and password and it gets validated in the code as below. If all is fine then the main form is displayed.
However, I am trying to get the username from textBox1 copied to a label "lblUserName" in the Mainform. How do I get this to work? I am able to get the text from textBox1 copied to a lbluser on the Logon form but can't get it over to the Mainform. Any help would be GREATLY appreciated.
public partial class Logon : Form
{
public Logon()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
NEF frm = new NEF();
if (textBox1.Text == "maphanga" && textBox2.Text == "marsha"
|| textBox1.Text == "nkosi" && textBox2.Text == "mdu"
|| textBox1.Text == "carrim" && textBox2.Text == "allerece"
|| textBox1.Text == "raphela" && textBox2.Text == "rachel"
|| textBox1.Text == "mazibuko" && textBox2.Text == "zoliswa")
{
this.DialogResult = DialogResult.OK;
}
else MessageBox.Show("Invalid username and or password supplied");
lbluser.Text = textBox1.Text;
frm.Close();
MessageBox.Show(lbluser.Text);
}
}
"I'm just so confused I can't remember my own name"
|
|
|
|
|
|
Why don't you add a property to the logon form:
...<br />
<br />
public string Username<br />
{<br />
get {return textBox1.Text}<br />
}<br />
...
And in the MainForm you add:
LogonForm oForm = new LogonForm();<br />
if( oForm.ShowDialog() == DialogResult.OK )<br />
{<br />
lbluser.Text = oForm.Username<br />
}<br />
else<br />
{<br />
}
Visit my blog at http://dotnetforeveryone.blogspot.com/
|
|
|
|
|
Brilliant. First suggestion that actualy worked. Much appreciated. I tried so many different suggestions and none of them worked.
Now I can sleep again!!!!!
|
|
|
|
|
Hello,
You have to care about Resourcess.
In the example the loggonForm is not going to be disposed.
If you allways want to instanciate a new LoggonForm, I would suggest to use a 'using' block, which is doing the disposing for you:
using(LogonForm oForm = new LogonForm())
{
if( oForm.ShowDialog() == DialogResult.OK )
{
lbluser.Text = oForm.Username
}
else
{
}
}
Or instanciate the Form once and hold the reference in your mainform, as long as you need it.
All the best,
Martin
|
|
|
|
|
Well, I can see two ways to accomplish what you want.
1) Set the constructor for the main form to receive a string as a parameter and display that string on the form. Something like this.
public partial class Logon : Form
{
public Logon()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
NEF frm = new NEF(textBox1.Text);
frm.ShowDialog();
Application.Exit();
}
}
public partial class NEF: Form
{
public NEF(string username)
{
lblUserName.Text = username;
}
}
2) You can set the textBox1 modifiers to public and call the logon form from the main form (that means that in Program.cs, you should set Application.Run(new NEF()). Here is an example
public partial class NEF:Form
{
public NEF()
{
}
private void FormLoad(object Sender, EventArgs e)
{
Logon frm = new Logon();
if (frm.ShowDialog() == DialogResult.OK)
{
this.lblUserName = frm.textBox1.Text;
}
}
}
public partial class Logon : Form
{
public Logon()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "maphanga" && textBox2.Text == "marsha"
|| textBox1.Text == "nkosi" && textBox2.Text == "mdu"
|| textBox1.Text == "carrim" && textBox2.Text == "allerece"
|| textBox1.Text == "raphela" && textBox2.Text == "rachel"
|| textBox1.Text == "mazibuko" && textBox2.Text == "zoliswa")
{
this.DialogResult = DialogResult.OK;
}
else MessageBox.Show("Invalid username and or password supplied");
lbluser.Text = textBox1.Text;
}
}
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
hi,
i have a textbox and a datagrid....wen i enter any text in the textbox and wen i click on an update button i want the datagrid to be updated.....
i know the code has to be written in the update button press....but i dont know how to proceed from here.....
please help.....
also any urls that will explain the basic datagrid usage will be good
thanking you
j
|
|
|
|
|
On the button click event write this code
dataGridView1.Rows.Add(textBox1.Text);
Of course you have to add one column to the datagridview at design time.
Trustapple wrote: also any urls that will explain the basic datagrid usage will be good
Try these links [^]
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
hi Andrei,
you are awesome.....
thankyou for helping me so much.......
hope to catch you again
cheers
jiju
j
|
|
|
|
|
I prinr line's text on X and Y location
I use "System.Drawing.Printing.PrintPageEventArgs e"
and evey time It do the task ,I cange only one text
on the page.
but it's run very slow.
I print about 2000 pages!!
how can I save the "event e" and add to the end one text and then print the page???
can I save It into file??? but remember that I have location X and Y
to the text and the line's
|
|
|
|
|
I think you can save it in a collection like : List<printpageeventargs>
Put that list as member variable.
|
|
|
|
|
How do you mean ???
How can It work's
|
|
|
|
|
hi all,
my question is regarding functional overloading.....
i know how functional overloading works.... but i would like to know wen all are we using functional overloading ie we use fn overloading wen we have multiple functions with same name......but my question is
why do we have to:
1)have multiple functions with same name......
2)can you give me very very simple code with some real life scenorio which will explain these to me......
also a simple explanation for delegates will also be appreciated both in cosole and windows form.......
thanking you in advance,
j
-- modified at 2:45 Tuesday 16th October, 2007
|
|
|
|
|
If you search on google using keywords ‘function overloading+c#’ or ‘delegates+c#’ you will get enough links to tutorials and samples.
If you face any specific problem while doing function overloading or while using delegates, let us know.
-Dave.
Dave Traister,
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
thank you Dave
j
|
|
|
|
|
Hi everyone.
I'm testing something and I ran into a problem..at least it's a problem for me. I've dragged and dropped the dataset object into a form (or project). I have an existing xml XSD. this schema is quite large and contains also relationships those I can see in visual studio as small diamond elements connected with lines to related tables.
i do this:
dsDataset.ReadXMLSchema("blabla.xsd");
and what I'd like to do, is to get the names of the relationships.. but it seems quite impossible, as dsDataset.Relations is not giving me any of those relations defined by <xsd:keyref>. How can I access these ?
thanks you in advance.
- Michal
|
|
|
|
|
hi, i was wondering....how do you determine when to use sockets in networking. What conditions or requirement that needs sockets. the socket is from "using system.net.socket"
Thanks in advance
|
|
|
|
|
Hi,
Sockets are used when you want to exchange data between several applications using TCP/IP or UDP protocol. Try this [^] article.
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
I development a project which has component at:
http://www.soft4science.com
I downloaded but i hav'nt got licence.
Please send me if:
+ You crack it.
+ You have license.
any people which same me. Pls Discuss with me.
-----------------------
thanks & best reguards.
Tuongnd80@yahoo.com
tuongnd
|
|
|
|
|
?????
Just buy the license. Only 299USD.
http://www.soft4science.com/products/MathMLControl/s4s_Order_MathMLControl.html
|
|
|
|
|
can somebody explain to me in C#
1>what are the different ways to call a function in C#?
2>how to declare a function with parameters?
3>how to call a function with parameters?
4>MOST IMP:how to return a value form a function?
its urgent.please explain in very simple terms
thanking you in advance
j
j
|
|
|
|
|
Your Ans~
Trustapple wrote: 1>what are the different ways to call a function in C#?
Just Write the function name from where you want to call with proper argumnet. suppose , Add(int a,int b) is a function you just call it by
Add(5,6), if its return some value then s=Add(5,6).
You can invoke a function using Deligation also.
Trustapple wrote: 2>how to declare a function with parameters?
int Add(int a,int b)
void AddString(Sring s1,string s2)
Trustapple wrote: 3>how to call a function with parameters?
That i already explain
Trustapple wrote: 4>MOST IMP:how to return a value form a function?
just Simply use return statement
int Add(int a,int b)
{
int c=a+b;
return c;
}
Happy Programming
-----
Abhijit
|
|
|
|
|
Awesome....Thanks a lot.
but i have a small doubt
"Just Write the function name from where you want to call with proper argument. suppose , Add(int a,int b) is a function you just call it by
Add(5,6), if its return some value then s=Add(5,6)."
i didnt understand this
now one more issue:
i wrote a code with two classes....
even with out linking the classes i am getting the correct output????
can you look into this and guide me where i am going wrong please......
class Program
{
int x;
int y;
int result;
char oper;
public int Add(int x, int y)
{
result = x + y;
return result;
}
public void display()
{
Console.WriteLine("{0}", result);
}
thanks again
class jiju
{
static void Main()
{
Program obj = new Program();
obj.Add(10, 20);
obj.display();
Console.ReadLine();
}
}
}
j
|
|
|
|
|
Trustapple wrote: Just Write the function name from where you want to call with proper argument. suppose , Add(int a,int b) is a function you just call it by
Add(5,6), if its return some value then s=Add(5,6)."
i didnt understand this
I just want to mean that if you have a function Add(int a ,int b) , u can call it by using Add(5,6)
that is
Void Add(int a,int b)
{
int c=a+b;
Console.Writeline(c.ToString());
}
Here no return , so u have to call it by Add(value1,value2)
and if the defination is like this , that its return the value
int Add(int a,int b)
{
return a+b;
}
Then u have to call it using result=Add(5,6);
Hope now it clear to u....
And ur code is correct.... what is the problem r u facing with it !!!!
Happy Programming
-----
Abhijit
|
|
|
|
|
Your code works, but there are several things you can change here.
class Program
{
public int Add(int x, int y)
{
int result = x + y;
return result;
}
public void display(int result)
{
Console.WriteLine("{0}", result);
}
}
class jiju
{
static void Main()
{
Program obj = new Program();
int result = obj.Add(10, 20);
obj.display(result);
Console.ReadLine();
}
}
or
class Program
{
public int Add(int x, int y)
{
int result = x + y;
return result;
}
}
class jiju
{
static void Main()
{
Program obj = new Program();
int result = obj.Add(10, 20);
Console.WriteLine("{0}",result);
Console.ReadLine();
}
}
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|