Here is some of my code
Dim myXmlTextWriter As XmlTextWriter = New XmlTextWriter(" C:\CPViewer\CPV iewer.xml", System.Text.Enc oding.Unicode
myXmlTextWriter .Formatting = System.Xml.Form atting.Indente
myXmlTextWriter .WriteStartElem ent("CPViewer"
myXmlTextWriter .WriteElementSt ring("Height", Me.Height
myXmlTextWriter .WriteElementSt ring("Width", Me.Width
'myXmlTextWrite r.WriteElementS tring("Backgrou nd", Me.BackgroundIm age
myXmlTextWriter .WriteElementSt ring("label2_To p", Label2.Top
myXmlTextWriter .WriteElementSt ring("label2_Le ft", Label2.Left
myXmlTextWriter .WriteElementSt ring("label2_He ight", Label2.Height
myXmlTextWriter .WriteElementSt ring("label2_Wi dth", Label2.Width
'myXmlTextWrite r.WriteElementS tring("label2_F ont", Label2.Font
'myXmlTextWrite r.WriteElementS tring("label2_F oreColor", Label2.ForeColo r
'myXmlTextWrite r.WriteElementS tring("label2_B ackColor", Label2.BackColo r
myXmlTextWriter .WriteEndElemen t(
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 1470
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\CPV iewer.xml", System.Text.Enc oding.Unicode) myXmlTextWriter .Formatting = System.Xml.Form atting.Indented myXmlTextWriter .WriteStartElem ent("CPViewer") myXmlTextWriter .WriteElementSt ring("Height", Me.Height) myXmlTextWriter .WriteElementSt ring("Width", Me.Width) 'myXmlTextWrite r.WriteElementS tring("Backgrou nd",
Me.BackgroundIm age)
myXmlTextWriter .WriteBinHex("B ackground", form.Background Image)
myXmlTextWriter .WriteStartElem ent("label2")
myXmlTextWriter .WriteElementSt ring("Top", label2.Top.ToSt ring())
myXmlTextWriter .WriteElementSt ring("Left", label2.Left.ToS tring())
myXmlTextWriter .WriteElementSt ring("Height",
label2.Height.T oString())
myXmlTextWriter .WriteElementSt ring("Width", label2.Width.To String())
myXmlTextWriter .WriteStartElem ent("Font")
myXmlTextWriter .WriteElementSt ring("Bold",
label2.Font.Bol d.ToString())
...
myXmlTextWriter .WriteEndElemen t()
myXmlTextWriter .WriteElementSt ring("ForeColor ",
label2.ForeColo r.ToString())
myXmlTextWriter .WriteElementSt ring("BackColor ",
label2.BackColo r.ToString())
myXmlTextWriter .WriteEndElemen t()
myXmlTextWriter .WriteEndElemen t() myXmlTextWriter .Flush() myXmlTextWriter .Close()
Hope this helps
Jay
"jcrouse" <an*******@disc ussions.microso ft.com> wrote in message
news:35******** *************** ***********@mic rosoft.com... Here is some of my code:
Dim myXmlTextWriter As XmlTextWriter = New
XmlTextWriter(" C:\CPViewer\CPV iewer.xml", System.Text.Enc oding.Unicode) myXmlTextWriter .Formatting = System.Xml.Form atting.Indented myXmlTextWriter .WriteStartElem ent("CPViewer") myXmlTextWriter .WriteElementSt ring("Height", Me.Height) myXmlTextWriter .WriteElementSt ring("Width", Me.Width) 'myXmlTextWrite r.WriteElementS tring("Backgrou nd",
Me.BackgroundIm age) myXmlTextWriter .WriteElementSt ring("label2_To p", Label2.Top) myXmlTextWriter .WriteElementSt ring("label2_Le ft", Label2.Left) myXmlTextWriter .WriteElementSt ring("label2_He ight", Label2.Height) myXmlTextWriter .WriteElementSt ring("label2_Wi dth", Label2.Width) 'myXmlTextWrite r.WriteElementS tring("label2_F ont", Label2.Font) 'myXmlTextWrite r.WriteElementS tring("label2_F oreColor",
Label2.ForeColo r) 'myXmlTextWrite r.WriteElementS tring("label2_B ackColor",
Label2.BackColo r) myXmlTextWriter .WriteEndElemen t() 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\CPV iewer.xml", System.Text.Enc oding.Unicode
myXmlTextWriter .Formatting = System.Xml.Form atting.Indente
myXmlTextWriter .WriteStartElem ent("CPViewer"
myXmlTextWriter .WriteStartElem ent("Form"
myXmlTextWriter .WriteElementSt ring("Height", Me.Height
myXmlTextWriter .WriteElementSt ring("Width", Me.Width
myXmlTextWriter .WriteElementSt ring("Backgroun d", OpenFileDialog1 .FileName
myXmlTextWriter .WriteEndElemen t(
myXmlTextWriter .WriteStartElem ent("Label2"
myXmlTextWriter .WriteElementSt ring("Top", Label2.Top.ToSt ring()
myXmlTextWriter .WriteElementSt ring("Left", Label2.Left.ToS tring()
myXmlTextWriter .WriteElementSt ring("Height", Label2.Height.T oString()
myXmlTextWriter .WriteElementSt ring("Width", Label2.Width.To String()
myXmlTextWriter .WriteElementSt ring("Font", Label2.Font.ToS tring()
myXmlTextWriter .WriteElementSt ring("ForeColor ", Label2.ForeColo r.ToString()
myXmlTextWriter .WriteElementSt ring("BackColor ", Label2.BackColo r.ToString()
myXmlTextWriter .WriteEndElemen t(
myXmlTextWriter .WriteEndElemen t(
myXmlTextWriter .Flush(
myXmlTextWriter .Close(
And here is the XML file it creates
<CPViewer><Form ><Height>600</Height><Width>8 00</Width><Backgrou nd>C:\CPViewer\ BackgroundImage .jpg</Background></Form><Label2><T op>58</Top><Left>42</Left><Height>40 </Height><Width>1 40</Width><Font>[Font: Name=Arial, Size=9.75, Units=3, GdiCharSet=0, GdiVerticalFont =False]</Font><ForeColor >Color [White]</ForeColor><Back Color>Color [Red]</BackColor></Label2></CPViewer
But I can't read in
The background line gives this error
An unhandled exception of type 'System.Argumen tException' 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.Invalid CastException' 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*******@disc ussions.microso ft.com> wrote in message
news:3C******** *************** ***********@mic rosoft.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\CPV iewer.xml", System.Text.Enc oding.Unicode)
myXmlTextWriter .Formatting = System.Xml.Form atting.Indented myXmlTextWriter .WriteStartElem ent("CPViewer") myXmlTextWriter .WriteStartElem ent("Form") myXmlTextWriter .WriteElementSt ring("Height", Me.Height) myXmlTextWriter .WriteElementSt ring("Width", Me.Width) myXmlTextWriter .WriteElementSt ring("Backgroun d", OpenFileDialog1 .FileName) myXmlTextWriter .WriteEndElemen t() myXmlTextWriter .WriteStartElem ent("Label2") myXmlTextWriter .WriteElementSt ring("Top", Label2.Top.ToSt ring()) myXmlTextWriter .WriteElementSt ring("Left", Label2.Left.ToS tring()) myXmlTextWriter .WriteElementSt ring("Height", Label2.Height.T oString()) myXmlTextWriter .WriteElementSt ring("Width", Label2.Width.To String()) myXmlTextWriter .WriteElementSt ring("Font", Label2.Font.ToS tring()) myXmlTextWriter .WriteElementSt ring("ForeColor ", Label2.ForeColo r.ToString()) myXmlTextWriter .WriteElementSt ring("BackColor ", Label2.BackColo r.ToString()) myXmlTextWriter .WriteEndElemen t() myXmlTextWriter .WriteEndElemen t()
myXmlTextWriter .Flush() myXmlTextWriter .Close()
And here is the XML file it creates:
<CPViewer><Form ><Height>600</Height><Width>8 00</Width><Backgrou nd>C:\CPViewer\ BackgroundImage .jpg</Background></Form><Label2><T op>58</Top><Left>42</Left><Height>40 </Height><Width>1 40</Width><Font>[Font: Name=Arial, Size=9.75, Units=3, GdiCharSet=0, GdiVerticalFont =False]</Font><ForeColor >Color [White]</ForeColor><Back Color>Color [Red]</BackColor></Label2></CPViewer>
But I can't read in.
The background line gives this error:
An unhandled exception of type 'System.Argumen tException' 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.Invalid CastException' 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**********@p lanet.nl> wrote in message
news:uL******** ******@TK2MSFTN GP12.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*******@disc ussions.microso ft.com> wrote in message
news:3C******** *************** ***********@mic rosoft.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\CPV iewer.xml", System.Text.Enc oding.Unicode) myXmlTextWriter .Formatting = System.Xml.Form atting.Indented myXmlTextWriter .WriteStartElem ent("CPViewer") myXmlTextWriter .WriteStartElem ent("Form") myXmlTextWriter .WriteElementSt ring("Height", Me.Height) myXmlTextWriter .WriteElementSt ring("Width", Me.Width) myXmlTextWriter .WriteElementSt ring("Backgroun d",
OpenFileDialog1 .FileName) myXmlTextWriter .WriteEndElemen t() myXmlTextWriter .WriteStartElem ent("Label2") myXmlTextWriter .WriteElementSt ring("Top", Label2.Top.ToSt ring()) myXmlTextWriter .WriteElementSt ring("Left", Label2.Left.ToS tring()) myXmlTextWriter .WriteElementSt ring("Height",
Label2.Height.T oString()) myXmlTextWriter .WriteElementSt ring("Width",
Label2.Width.To String()) myXmlTextWriter .WriteElementSt ring("Font", Label2.Font.ToS tring()) myXmlTextWriter .WriteElementSt ring("ForeColor ",
Label2.ForeColo r.ToString()) myXmlTextWriter .WriteElementSt ring("BackColor ",
Label2.BackColo r.ToString()) myXmlTextWriter .WriteEndElemen t() myXmlTextWriter .WriteEndElemen t()
myXmlTextWriter .Flush() myXmlTextWriter .Close()
And here is the XML file it creates:
<CPViewer><Form ><Height>600</Height><Width>8 00</Width><Backgrou nd>C:\CPViewe
r\BackgroundIma ge.jpg</Background></Form><Label2><T op>58</Top><Left>42</Left<Height>40</Height><Width>1 40</Width><Font>[Font: Name=Arial, Size=9.75,
Units=3, GdiCharSet=0, GdiVerticalFont =False]</Font><ForeColor >Color
[White]</ForeColor><Back Color>Color [Red]</BackColor></Label2></CPViewer> But I can't read in.
The background line gives this error:
An unhandled exception of type 'System.Argumen tException' 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.Invalid CastException' 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 XmlSerializatio n.
My concern with XmlSerializatio n & 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**********@p lanet.nl> wrote in message
news:OD******** ******@TK2MSFTN GP11.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 XmlSerializatio n.
My concern with XmlSerializatio n & 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 SerializeFontOb ject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(me m, fnt)
Return Convert.ToBase6 4String(mem.ToA rray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
Private Function DeserializeFont Object(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Co nvert.FromBase6 4String(fnt))
Try
Return DirectCast(bf.D eserialize(mem) , Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
/// 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. When it completes, it can call a success, or a failure
function. The names of these success, or failure functions will differ,
and I'd like to know how I can pass the name of a function to my tool,
and how my tool can call the function, using that...
|
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 is started from a shell script. And not having the
permissions to execute such ones I'll try writing a .py script (with the
shebang that I allready knows will do the job) to call another .py
script like the original shell script does.
|
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 what I really should do. I've had a
look through Programming Python and the Python Cookbook, which have given me
ideas, but nothing has gelled yet, so I thought I'd put the question to the
community. But first, let me be a little more detailed...
|
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 folks might find to taste.
Here's the code - first the 'engine', then some code demonstrating the
usage patterns.
For me (and maybe for some of you), it promotes readability and some
|
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: 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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |