Here is some of my code
Dim myXmlTextWriter As XmlTextWriter = New XmlTextWriter("C:\CPViewer\CPViewer.xml", System.Text.Encoding.Unicode
myXmlTextWriter.Formatting = System.Xml.Formatting.Indente
myXmlTextWriter.WriteStartElement("CPViewer"
myXmlTextWriter.WriteElementString("Height", Me.Height
myXmlTextWriter.WriteElementString("Width", Me.Width
'myXmlTextWriter.WriteElementString("Background", Me.BackgroundImage
myXmlTextWriter.WriteElementString("label2_Top", Label2.Top
myXmlTextWriter.WriteElementString("label2_Left", Label2.Left
myXmlTextWriter.WriteElementString("label2_Height" , Label2.Height
myXmlTextWriter.WriteElementString("label2_Width", Label2.Width
'myXmlTextWriter.WriteElementString("label2_Font", Label2.Font
'myXmlTextWriter.WriteElementString("label2_ForeCo lor", Label2.ForeColor
'myXmlTextWriter.WriteElementString("label2_BackCo lor", Label2.BackColor
myXmlTextWriter.WriteEndElement(
myXmlTextWriter.Flush(
myXmlTextWriter.Close(
As you can tell by the comments I'm not sure how to write out anything but text strings. How do I write out other properties such as font types, color and images
Thank you
Joh 13 1449
John,
With an XmlTextWriter, I would just are you are for the label. For an Image,
I would use WriteBase64 or WriteBinHex. For Font I would write each element
of the Font, For Color I would use Color.ToString. You may be able to use
ToString on Font also...
However I consider using nested elements, something like: Dim myXmlTextWriter As XmlTextWriter = New
XmlTextWriter("C:\CPViewer\CPViewer.xml", System.Text.Encoding.Unicode) myXmlTextWriter.Formatting = System.Xml.Formatting.Indented myXmlTextWriter.WriteStartElement("CPViewer") myXmlTextWriter.WriteElementString("Height", Me.Height) myXmlTextWriter.WriteElementString("Width", Me.Width) 'myXmlTextWriter.WriteElementString("Background",
Me.BackgroundImage)
myXmlTextWriter.WriteBinHex("Background", form.BackgroundImage)
myXmlTextWriter.WriteStartElement("label2")
myXmlTextWriter.WriteElementString("Top", label2.Top.ToString())
myXmlTextWriter.WriteElementString("Left", label2.Left.ToString())
myXmlTextWriter.WriteElementString("Height",
label2.Height.ToString())
myXmlTextWriter.WriteElementString("Width", label2.Width.ToString())
myXmlTextWriter.WriteStartElement("Font")
myXmlTextWriter.WriteElementString("Bold",
label2.Font.Bold.ToString())
...
myXmlTextWriter.WriteEndElement()
myXmlTextWriter.WriteElementString("ForeColor",
label2.ForeColor.ToString())
myXmlTextWriter.WriteElementString("BackColor",
label2.BackColor.ToString())
myXmlTextWriter.WriteEndElement()
myXmlTextWriter.WriteEndElement() myXmlTextWriter.Flush() myXmlTextWriter.Close()
Hope this helps
Jay
"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com... Here is some of my code:
Dim myXmlTextWriter As XmlTextWriter = New
XmlTextWriter("C:\CPViewer\CPViewer.xml", System.Text.Encoding.Unicode) myXmlTextWriter.Formatting = System.Xml.Formatting.Indented myXmlTextWriter.WriteStartElement("CPViewer") myXmlTextWriter.WriteElementString("Height", Me.Height) myXmlTextWriter.WriteElementString("Width", Me.Width) 'myXmlTextWriter.WriteElementString("Background",
Me.BackgroundImage) myXmlTextWriter.WriteElementString("label2_Top", Label2.Top) myXmlTextWriter.WriteElementString("label2_Left", Label2.Left) myXmlTextWriter.WriteElementString("label2_Height" , Label2.Height) myXmlTextWriter.WriteElementString("label2_Width", Label2.Width) 'myXmlTextWriter.WriteElementString("label2_Font", Label2.Font) 'myXmlTextWriter.WriteElementString("label2_ForeCo lor",
Label2.ForeColor) 'myXmlTextWriter.WriteElementString("label2_BackCo lor",
Label2.BackColor) myXmlTextWriter.WriteEndElement() myXmlTextWriter.Flush() myXmlTextWriter.Close()
As you can tell by the comments I'm not sure how to write out anything but
text strings. How do I write out other properties such as font types, color
and images? Thank you, John
Well, I got the nested elements working. The fonts and color are not working, and neither is the background image. I can write the parameters to the XML file but can't read it in. I can't figure out the syntax. Here is my code to write out the parameters
Dim myXmlTextWriter As XmlTextWriter = New XmlTextWriter("C:\CPViewer\CPViewer.xml", System.Text.Encoding.Unicode
myXmlTextWriter.Formatting = System.Xml.Formatting.Indente
myXmlTextWriter.WriteStartElement("CPViewer"
myXmlTextWriter.WriteStartElement("Form"
myXmlTextWriter.WriteElementString("Height", Me.Height
myXmlTextWriter.WriteElementString("Width", Me.Width
myXmlTextWriter.WriteElementString("Background", OpenFileDialog1.FileName
myXmlTextWriter.WriteEndElement(
myXmlTextWriter.WriteStartElement("Label2"
myXmlTextWriter.WriteElementString("Top", Label2.Top.ToString()
myXmlTextWriter.WriteElementString("Left", Label2.Left.ToString()
myXmlTextWriter.WriteElementString("Height", Label2.Height.ToString()
myXmlTextWriter.WriteElementString("Width", Label2.Width.ToString()
myXmlTextWriter.WriteElementString("Font", Label2.Font.ToString()
myXmlTextWriter.WriteElementString("ForeColor", Label2.ForeColor.ToString()
myXmlTextWriter.WriteElementString("BackColor", Label2.BackColor.ToString()
myXmlTextWriter.WriteEndElement(
myXmlTextWriter.WriteEndElement(
myXmlTextWriter.Flush(
myXmlTextWriter.Close(
And here is the XML file it creates
<CPViewer><Form><Height>600</Height><Width>800</Width><Background>C:\CPViewer\BackgroundImage.jpg</Background></Form><Label2><Top>58</Top><Left>42</Left><Height>40</Height><Width>140</Width><Font>[Font: Name=Arial, Size=9.75, Units=3, GdiCharSet=0, GdiVerticalFont=False]</Font><ForeColor>Color [White]</ForeColor><BackColor>Color [Red]</BackColor></Label2></CPViewer
But I can't read in
The background line gives this error
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dl
Additional information: Cannot bind to property 'Background' on target control
And the font and color lines give this error
An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dl
Additional information: Invalid cast from System.String to System.Drawing.Font
I tried your suggestions but guess I didn't get the syntax correct
Thank you
Joh
I don't really know what you are trying to do, through, it looks like a job
for dynamic properties. - Jared http://msdn.microsoft.com/library/de...ingstorage.asp
"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com... Well, I got the nested elements working. The fonts and color are not working, and neither is the background image. I can write the parameters to the XML file but can't read it in. I can't figure out the syntax. Here is my code to write out the parameters:
Dim myXmlTextWriter As XmlTextWriter = New XmlTextWriter("C:\CPViewer\CPViewer.xml", System.Text.Encoding.Unicode)
myXmlTextWriter.Formatting = System.Xml.Formatting.Indented myXmlTextWriter.WriteStartElement("CPViewer") myXmlTextWriter.WriteStartElement("Form") myXmlTextWriter.WriteElementString("Height", Me.Height) myXmlTextWriter.WriteElementString("Width", Me.Width) myXmlTextWriter.WriteElementString("Background", OpenFileDialog1.FileName) myXmlTextWriter.WriteEndElement() myXmlTextWriter.WriteStartElement("Label2") myXmlTextWriter.WriteElementString("Top", Label2.Top.ToString()) myXmlTextWriter.WriteElementString("Left", Label2.Left.ToString()) myXmlTextWriter.WriteElementString("Height", Label2.Height.ToString()) myXmlTextWriter.WriteElementString("Width", Label2.Width.ToString()) myXmlTextWriter.WriteElementString("Font", Label2.Font.ToString()) myXmlTextWriter.WriteElementString("ForeColor", Label2.ForeColor.ToString()) myXmlTextWriter.WriteElementString("BackColor", Label2.BackColor.ToString()) myXmlTextWriter.WriteEndElement() myXmlTextWriter.WriteEndElement()
myXmlTextWriter.Flush() myXmlTextWriter.Close()
And here is the XML file it creates:
<CPViewer><Form><Height>600</Height><Width>800</Width><Background>C:\CPViewer\BackgroundImage.jpg</Background></Form><Label2><Top>58</Top><Left>42</Left><Height>40</Height><Width>140</Width><Font>[Font: Name=Arial, Size=9.75, Units=3, GdiCharSet=0, GdiVerticalFont=False]</Font><ForeColor>Color [White]</ForeColor><BackColor>Color [Red]</BackColor></Label2></CPViewer>
But I can't read in.
The background line gives this error:
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll Additional information: Cannot bind to property 'Background' on target control.
And the font and color lines give this error:
An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dll Additional information: Invalid cast from System.String to System.Drawing.Font.
I tried your suggestions but guess I didn't get the syntax correct.
Thank you, John
Hi John,
Now you should have readed my text that it is easier when you try to read an
XML dataset to write that as well as a XML dataset. However you did not give
any comments on that in my opinion.
(To give Jay a little extra information as well)
Cor
Cor,
Your text where?
Jay
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl... Hi John,
Now you should have readed my text that it is easier when you try to read
an XML dataset to write that as well as a XML dataset. However you did not
give any comments on that in my opinion.
(To give Jay a little extra information as well)
Cor
John,
Hmm...
I was concerned that the Font would add extra info, which it did. Rather
then using Font.ToString it might be easier to use each property of Font, as
you do with Label.
I was not expecting Color to add extra info! If your colors are only named
colors you could use Color.Name to write & Color.FromName to read. However
this fails with non-named colors. You could always use Color.ToArgb &
Color.FromArgb instead.
Hope this helps
Jay
"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com... Well, I got the nested elements working. The fonts and color are not
working, and neither is the background image. I can write the parameters to
the XML file but can't read it in. I can't figure out the syntax. Here is my
code to write out the parameters: Dim myXmlTextWriter As XmlTextWriter = New
XmlTextWriter("C:\CPViewer\CPViewer.xml", System.Text.Encoding.Unicode) myXmlTextWriter.Formatting = System.Xml.Formatting.Indented myXmlTextWriter.WriteStartElement("CPViewer") myXmlTextWriter.WriteStartElement("Form") myXmlTextWriter.WriteElementString("Height", Me.Height) myXmlTextWriter.WriteElementString("Width", Me.Width) myXmlTextWriter.WriteElementString("Background",
OpenFileDialog1.FileName) myXmlTextWriter.WriteEndElement() myXmlTextWriter.WriteStartElement("Label2") myXmlTextWriter.WriteElementString("Top", Label2.Top.ToString()) myXmlTextWriter.WriteElementString("Left", Label2.Left.ToString()) myXmlTextWriter.WriteElementString("Height",
Label2.Height.ToString()) myXmlTextWriter.WriteElementString("Width",
Label2.Width.ToString()) myXmlTextWriter.WriteElementString("Font", Label2.Font.ToString()) myXmlTextWriter.WriteElementString("ForeColor",
Label2.ForeColor.ToString()) myXmlTextWriter.WriteElementString("BackColor",
Label2.BackColor.ToString()) myXmlTextWriter.WriteEndElement() myXmlTextWriter.WriteEndElement()
myXmlTextWriter.Flush() myXmlTextWriter.Close()
And here is the XML file it creates:
<CPViewer><Form><Height>600</Height><Width>800</Width><Background>C:\CPViewe
r\BackgroundImage.jpg</Background></Form><Label2><Top>58</Top><Left>42</Left<Height>40</Height><Width>140</Width><Font>[Font: Name=Arial, Size=9.75,
Units=3, GdiCharSet=0, GdiVerticalFont=False]</Font><ForeColor>Color
[White]</ForeColor><BackColor>Color [Red]</BackColor></Label2></CPViewer> But I can't read in.
The background line gives this error:
An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll Additional information: Cannot bind to property 'Background' on target
control. And the font and color lines give this error:
An unhandled exception of type 'System.InvalidCastException' occurred in
mscorlib.dll Additional information: Invalid cast from System.String to
System.Drawing.Font. I tried your suggestions but guess I didn't get the syntax correct.
Thank you, John
Cor,
Yes using a DataSet is an option, as is using XmlSerialization.
My concern with XmlSerialization & DataSets, is that they still will not
save Colors, Fonts & Controls, so John is back to where he started. Hence I
was staying with the XmlWriter, as you can manually write out the Colors,
Fonts and Controls.
Hope this helps
Jay
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OD**************@TK2MSFTNGP11.phx.gbl... Hi Jay,
Another thread
http://groups.google.com/groups?selm...TNGP11.phx.gbl Cor
Your text where?
Hi Jay, Yes using a DataSet is an option, as is using XmlSerialization.
My concern with XmlSerialization & DataSets, is that they still will not save Colors, Fonts & Controls, so John is back to where he started. Hence I was staying with the XmlWriter, as you can manually write out the Colors, Fonts and Controls.
It is posible to serialize a font object and put that in a dataset however
it can in seperate string characters as well in my opinion.
I do not know if you saw it, Tom supplied this code some weeks ago to this
newsgroup. So the font can just be stored as a string and than be
deserialized.
However I will choose for 3 items in a table that makes the dataset as well
(human) readable.
Cor
\\\Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
///
Hi Jay,
However this is not a should, this is what I prefer because working with a
dataset is so simple, and working with XMLdocuments gives often problems.
(As well with me while I an not unexpirienced with it)
However that is the nice thing from dotNet as I always says, do it the way
that fits you the most (when it is not real bad.)
However when I am not using the dataset, than I would also not use the
ds.ReadXML as that is now done by John,
My reason, the same as I interpretted what you wrote, the complete
flexibility of XML.
Before you understand me wrong
Cor
Well I tried to use the ToArgB and FromArgB parameters but I don't seem to understand the syntax
Any more Ideas
John
I also tried to use the individual parameters for the font, like, bold, size, name and such. I was able to write them out but still couldn't read them in
Help
John
John,
Did you look up the functions in Help to see samples of how to use them?
To write the file you would use something like:
myXmlTextWriter.WriteElementString("ForeColor",
label2.ForeColor.ToArgB())
In your reader you would use something like:
If myXmlTextReader.NodeType = XmlNodeType.Element AndAlso
myXmlTextReader.Name = "ForeColor" Then
label2.ForColor = Color.FromArgB(myXmlTextReader.Value)
End If
The Font you would need to do the same thing. In your read code create a new
font from the values stored in the XML.
Hope this helps
Jay
"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com... Well I tried to use the ToArgB and FromArgB parameters but I don't seem to
understand the syntax. Any more Ideas, John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Randell D. |
last post by:
Folks,
I'm sure this can be done legally, and not thru tricks of the trade - I
hope someone can help.
I'm writing a 'tool' (a function) which can be used generically in any
of my projects. ...
|
by: Christian |
last post by:
From a not even newbie:
Without knowing much about Python (yet) I'm trying to install the CMS
Zope via FTP (with the well documented changes to make it work on an
Apache server).
By birth Zope...
|
by: Paul Cochrane |
last post by:
Hi all,
I've got an application that I'm writing that autogenerates python code
which I then execute with exec(). I know that this is not the best way to
run things, and I'm not 100% sure as to...
|
by: aum |
last post by:
Hi,
I'm a Python programmer, just starting to get into javascript. On reading
some of the js guides, and not liking any of the OO usage patterns I saw,
I've cooked up something which python...
|
by: sagar |
last post by:
Hi,
I have a C file(add.c) in which i have a function called add.now
i want to call the same add function from another file sub.c .Can any1
tell how to do that...
Thanks in advance
Mark
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |