I am using visual studio 2010 to create a windows form for reading in data from an xml file and displaying it in a form. any code relating to dynamically changing the content of a label or textbox with this information would be much appreciated. At the moment i can read in an xml file and display some content in the console.
我正在使用visual studio 2010来创建一个窗口表单,用于从xml文件中读取数据并在表单中显示它。任何与使用此信息动态更改标签或文本框内容相关的代码都将非常感激。目前我可以读取xml文件并在控制台中显示一些内容。
thank you for taking the time to read this.
感谢您抽出时间来阅读。
2 个解决方案
#1
1
Once you've loaded your Xml, all you need to do is set the .Text
property of a TextBox or Label control:
一旦你加载了你的Xml,你需要做的就是设置TextBox或Label控件的.Text属性:
string xmlData = "<xml>\r\n<tag>This is my xml</tag></xml";
myTextBox.Text = xmlData;
You said you can get Xml content to display in the console, you'll just be directing the output to a WinForm control, rather than the console. Also, if you use a TextBox
, you'll want to set it's Multiline
property to true
.
你说你可以在控制台中显示Xml内容,你只需将输出定向到WinForm控件,而不是控制台。此外,如果使用TextBox,则需要将其Multiline属性设置为true。
You can read more about TextBox controls and Label controls on MSDN.
您可以在MSDN上阅读有关TextBox控件和Label控件的更多信息。
#2
0
Use XML parser to extract elements
使用XML解析器提取元素
http://msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspx
http://msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspx
then use control properties textBox.text = someString
然后使用控件属性textBox.text = someString
#1
1
Once you've loaded your Xml, all you need to do is set the .Text
property of a TextBox or Label control:
一旦你加载了你的Xml,你需要做的就是设置TextBox或Label控件的.Text属性:
string xmlData = "<xml>\r\n<tag>This is my xml</tag></xml";
myTextBox.Text = xmlData;
You said you can get Xml content to display in the console, you'll just be directing the output to a WinForm control, rather than the console. Also, if you use a TextBox
, you'll want to set it's Multiline
property to true
.
你说你可以在控制台中显示Xml内容,你只需将输出定向到WinForm控件,而不是控制台。此外,如果使用TextBox,则需要将其Multiline属性设置为true。
You can read more about TextBox controls and Label controls on MSDN.
您可以在MSDN上阅读有关TextBox控件和Label控件的更多信息。
#2
0
Use XML parser to extract elements
使用XML解析器提取元素
http://msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspx
http://msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspx
then use control properties textBox.text = someString
然后使用控件属性textBox.text = someString