|
set modifiers of your form2`s label to "public" in properties
then in button`s click event ,writes these codes
form2 frm = new form2();
frm.label2.Text = textbox1.Text;
frm.Show();
hope it will help...
Becoming Programmer...
|
|
|
|
|
I have tried that but it comes up with this error when you click the button:
Additional information: Object reference not set to an instance of an object.
I do not understand the other comments people have made as I am still very new to c#.
Lucy
|
|
|
|
|
i think you are clicking button when your textbox value is null
Becoming Programmer...
|
|
|
|
|
No the error still occurs when the textbox has text in it.
|
|
|
|
|
you are doing some mistakes
Becoming Programmer...
|
|
|
|
|
Yup - one of the first mistakes is making a control public. You really shouldn't make controls public because you have opened up the whole scope of what the control can do to another unrelated instance.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Another way is like this:
Add another Label to your class variables:
private System.Windows.Forms.Label Form2Label;
Create a method in form one like this:
public void getLabel(Label label) {
Form2Label = label;
}
Then, when you click the button in Form1 just add a bit of extra code.
Form2Label.Text = this.TextBox.Text;
Now when you start Form2, run the method, and pass it the label.
Form1.getLabel(this.label);
That should work. You'd have to try it out.
|
|
|
|
|
Try using this way
declare a bool variable in form2 with public accessiblity
like
<br />
public bool clicked;<br />
and in the form load event you can check like
<br />
if (clicked)<br />
{<br />
}<br />
in form1's button1's click event write
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
Form2 frm = new Form2();<br />
frm.clicked = true;<br />
frm.Show();<br />
}<br />
Paras Kaneriya The difference between genius and stupidity is that genius has its limits.
|
|
|
|
|
|
Use XPath. In particular the XmlDocument.SelectSingleNode(...) function.
|
|
|
|
|
:(Its not working.....
stil it showing error
System.Xml.XmlException: The tag from namespace is not expected. Line 3, position 2. at System.Xml.XmlReader.ReadElementString(String name) at ElsBook.First.Button1_Click(Object sender, EventArgs e)
If we give multiple number of read stmt, its working
|
|
|
|
|
try this
XmlDocument xmldoc = new XmlDocument();
FileStream fs = new FileStream(Xmlfilepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
xmldoc.Load(fs);
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("ABC");
for (int a = 0; a < xmlnode.Count; a++)
{
if (xmlnode[a].Attributes[0].Value == "requirednode")
{
}
}
Becoming Programmer...
|
|
|
|
|
Still some error......
Inside for loop.....
|
|
|
|
|
It would help everyone if you could provide a sample of the XML (even a subset would be good) and information about the error you are encountering. Saying you've run into an error leaves things up to a lot of interpretation.
[modification]And sample code showing how you are trying to read the file and go to the specific node would be helpful as well.[/modification]
|
|
|
|
|
This is the xml
<?xml version="1.0" encoding="UTF-8" ?>
<family>
<name gender="male">
<firstname>Tom</firstname>
<lastname>Smith</lastname>
</name>
</family>
and the code is --------
FileStream fs = new FileStream("D:\\Myfolder\\gender.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
xmldoc.Load(fs);
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("name");
for (int a = 0; a < xmlnode.Count; a++)
{
if (xmlnode[a].Attributes[0].Value == "gender")
// match your attributes
{ //codes
lblcnt.Text=a.ToString();
String firstNameValue = reader.ReadElementString("gender");
Lblmsg.Text=" FirstName: "+firstNameValue;
}
I tried this one also=======
XmlTextReader reader = new XmlTextReader ("D:\\Myfolder\\gender.xml");
XmlDocument xmldoc = new XmlDocument();
XmlTextReader reader = new XmlTextReader ("C:\\gender.xml");
try
{
while (!reader.EOF)
{
reader.Read();
if(reader.IsStartElement() )
{
reader.Read();
xmldoc.SelectSingleNode("family/name/firstname");
XmlNode xmlnode1=xmldoc.GetElementsByTagName("firstname");
String firstNameValue = reader.ReadElementString("firstname");
xmldoc.SelectSingleNode("lastname");
String lastNameValue = reader.ReadElementString("lastname");
Lblmsg.Text=" FirstName: "+firstNameValue + " LastName: " + lastNameValue;
}
}
reader.Close();
}
catch (Exception err )
{
Lblmsg.Text="Error: " + err.ToString();
}
-- modified at 23:06 Wednesday 12th September, 2007
|
|
|
|
|
Hi,
i am working in windows application of C#
i am using hash table.
i want to add data to hash table from datatable named DTSchool. I have a school name in combobox. when iselect school in combo it takes the curresponding SchoolID from the datatable
i want to know how to write code for that. i wrote like this
List.Add(SchoolDT.Rows[cboSchool.SelectedIndex]["SchoolID"],cboSchool.Text.ToString());
.But it is not taking value from datatable.Please help me regarding this problem?
|
|
|
|
|
Hi,
What is the Type of SchoolID? I am assuming it is "int" then you can try to write this line;
List.Add((int)SchoolDT.Rows[cboSchool.SelectedIndex]["SchoolID"],cboSchool.Text.ToString());
Mert Kantarcıoğlu
|
|
|
|
|
|
try reading these
1[^]
2[^]
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
If the 'TabAlignment' of a 'tabControl' is set to 'Left', the Controls headers text is aligned vertical.
Can anybody please introduce me to a way to realign (or rotate) the tabs header text so its displayed horizontal, while the headers still are on the left of the control?
Thanks in advance
-Soo
|
|
|
|
|
|
My question is actually in the subject. I'm tring to stop execution of code until webbrowser reloads the page, but the point is that most of it is coming in the background using AJAX httprequests so browser's DocumentCompleted event is raised to early while most of the document is still on the flight. How can I achieve the same effect as in mentioned event when AJAX stuff needs to be taken into consideration? should i monitor for net requests and responses coming in and out? it seems really complicated. Anybody has some idea?
|
|
|
|
|
completely no ideas? for now i made a timer but it assumes that quality of a connection is fine and has a constant interval which is not good and fails sometimes ..
|
|
|
|
|
When declaring:
[DllImport("kernel32.dll")]
public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
It dosnt seem to matter what argument datatypes you use, for instance, this works aswell:
[DllImport("kernel32.dll")]
public static extern UInt32 OpenProcess(uint dwDesiredAccess, uint bInheritHandle, Int32 dwProcessId);
Question 1:
What should you think of when declaring imported functions? Should you try to match the c/c++ datatype to its c# datatype couterpart? (For instance, for c++ int, c# Int32). Or does it not matter?
Question 2:
Arguments that are pointers. I dont quite understand how IntPtr etc works since im quite new to c#. But if a function has a parameter that is a pointer (int* return_val for instance. Should you use a IntPtr for that? Or an unsafe c# pointer?
Question 3:
Arguments that are typedef'ed types, for instance handles that are a c++ (void*). Should you use c# unsafe void*? Or is an int just as fine? Are there any rules for this? For instance, HWND is a UInt32 or something like that..
Question 4:
The "out" parameter, should it be used for c++ pointers and references that returns values (non const)?
Thanks.
|
|
|
|
|
Others might give you a more complete answer, but I usually end up here[^] for interop stuff.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
|
|
|
|