本文介绍了XML写作和阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码写入XML文件


myXmlTextWriter.Formatting = System.Xml.Formatting.Indente

myXmlTextWriter.WriteStartElement( CPViewer

myXmlTextWriter.WriteElementString(" Height",InputBoxHeight

myXmlTextWriter.WriteElementString(" Width",InputBoxWidth

'' myXmlTextWriter.WriteElementString(" Background",(OpenFileDialog1.FileName)

myXmlTextWriter.WriteElementString(" label1.Top",label1.Top

myXmlTextWriter.WriteElementString(" label1.Left",label1.Left

myXmlTextWriter.WriteElementString(" label1.Height",label1.Height

myXmlTextWriter.WriteElementString(" label1.Width",label1 .Width

myXmlTextWriter.WriteEndElement(

myXmlTextWriter.Flush(

myXmlTextWriter.Close(


)这是XML输出


< CPViewer>< Height&g吨; 600℃; /高度><宽度> 800℃; /宽度>< label1.Top> 200℃; /label1.Top>< label1.Left> 152< /label1.Left>< label1.Height> 23℃; /label1.Height><label1.Width>100</label1.Width></CPViewer


以下是读者的代码


DataSet1.ReadXml(" C:\ CPViewer\LD.xml"

Me.DataBindings.Add(New Binding(" Height",DataSet1," CPViewer.Height" )

Me.DataBindings.Add(New Binding(" Width",DataSet1," CPViewer.Width")

Me.DataBindings.Add(New Binding(") ; label1.Top",DataSet1," CPViewer.label1_Top")

''Me.DataBindings.Add(New Binding(" BackgroundImage",DataSet1," CPViewer.BackgroundImage")

Me.BackgroundImage =(Image.FromFile(" C:\ CPViewer \ BackgroundImage.jpg")

Me.CenterToScreen(


当我尝试阅读它时将读取 ;身高"和宽度正确地排列和定位表单但是当它读取Label1.top时我得到以下错误


发生了''Syste,.ArgumentException'类型的未处理异常i $ / $
system.windows.forms.dl


附加信息:无法绑定到目标控件上的''label1.Top''


我在这里缺少什么


谢谢

John

I am using the following code to write to an XML file

myXmlTextWriter.Formatting = System.Xml.Formatting.Indente
myXmlTextWriter.WriteStartElement("CPViewer"
myXmlTextWriter.WriteElementString("Height", InputBoxHeight
myXmlTextWriter.WriteElementString("Width", InputBoxWidth
''myXmlTextWriter.WriteElementString("Background", (OpenFileDialog1.FileName)
myXmlTextWriter.WriteElementString("label1.Top", label1.Top
myXmlTextWriter.WriteElementString("label1.Left", label1.Left
myXmlTextWriter.WriteElementString("label1.Height" , label1.Height
myXmlTextWriter.WriteElementString("label1.Width", label1.Width
myXmlTextWriter.WriteEndElement(
myXmlTextWriter.Flush(
myXmlTextWriter.Close(

Here is the XML output

<CPViewer><Height>600</Height><Width>800</Width><label1.Top>200</label1.Top><label1.Left>152</label1.Left><label1.Height>23</label1.Height><label1.Width>100</label1.Width></CPViewer

Here is the code from the reader

DataSet1.ReadXml("C:\CPViewer\LD.xml"
Me.DataBindings.Add(New Binding("Height", DataSet1, "CPViewer.Height")
Me.DataBindings.Add(New Binding("Width", DataSet1, "CPViewer.Width")
Me.DataBindings.Add(New Binding("label1.Top", DataSet1, "CPViewer.label1_Top")
''Me.DataBindings.Add(New Binding("BackgroundImage", DataSet1, "CPViewer.BackgroundImage")
Me.BackgroundImage = (Image.FromFile("C:\CPViewer\BackgroundImage.jpg")
Me.CenterToScreen(

When I try to read it in will will read the "Height" and "Width" lines and position the form properly but when it reads the "Label1.top" line I get the following error

An unhandled exception of type ''Syste,.ArgumentException'' occurred i
system.windows.forms.dl

Additional Information: Cannot bind to property ''label1.Top'' on target control

What am I missing here

Thank you
John

推荐答案




这篇关于XML写作和阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:11