Hi Henry,
If I understand your question correctly, you want to know if you can store
specific Control-building information in an XML file. The answer is yes.
Again, hoping I understand you fully, I am doing a similar type of project.
I'm building a "simple" printing engine that can be plugged into any .Net
application to create print jobs. This is a "generic" print engine, that
works with documents made up of rectangles containing various kinds of data
in them, such as formatted text, images, boxes, lines, and database data.
One of the requirements is that a document can be saved and/or loaded from a
file.
Now each of these "PrintEleme nt" types is a Control that can be used on a
"PagePanel" Control to visually build the print document. The "PagePanel"
Control can be hosted in any .Net Windows Form, and is a container for
"PrintEleme nt" Controls. All "PrintEleme nt" Controls share certain
characteristics . They can be transparent, or have a colored background. They
can be resized, dragged for re-positioning, and each can bring up a Dialog
Box to set various properties of the Control, such as Font, Background
Color, Border Width and Color, and so on. They are all highlighted by a
purple outline when the mouse hovers over them, and they can overlaid in
various Z-Orders.
So, I created a base class called "PrintEleme nt" that is derived from
UserControl. I gave it all the basic properties and functionality shared
among all "PrintEleme nt" classes. Then I created a derived "PrintEleme nt"
Control class for each different type of PrintElement, to handle the
different behaviors, such as being able to select an image for an
"ImagePrintElem ent" or a DataSource for a "TablePrintElem ent."
Now, as you know, a System.Windows. Forms.Control class cannot be serialized
as XML. But I wanted to be able to save a print document in an XML format
for cross-platform compatibility and other reasons. So, what I did was to
create a "PrinterDocumen t" class that could be serialized as XML. This is a
container class for "PrintElementDa ta" classes. I also created a base
"PrintElementDa ta" class that could be serialized as XML. It contained all
the information (data) needed to populate a "PrintEleme nt" base class, in a
serializable (as XML) format. For example, for Font, I created a "FontData"
class which holds all of the characteristics of a Font (which also cannot be
serialized as XML). For colors, I used the integer value of the given
System.Color (a Color can be converted to and from an Int32). And so on.
From this I derived a "PrintElementDa ta" class for each "PrintEleme nt"
class that I had, one for each. Then I added functionality to the
"PagePanel" Control that enables it to open an XML file, deserialize it to a
"PrinterDocumen t" class with a Collection of any number of
"PrintElementDa ta"-derived classes in it as a Collection. It uses Reflection
to discover the exact type of each "PrintElementDa ta" instance, and then
assigns it to the appropriate "PrintEleme nt"-derived class, which it then
adds to its Controls Collection. It can also save its current state to a
file by doing the opposite. It creates an instance of "PrinterDocumen t," and
adds the "PrintElementDa ta" instance from each "PrintEleme nt" in the page to
the "PrinterDocumen t" "PrintElementDa taCollection." Then it serializes that
as an XML file.
So, the basic principle is this: You can't actually serialize a Control, but
you *can* serialize the properties of the Control, which can then be used to
re-build the Control from a deserialized class at run-time.
--
HTH,
Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist
A lifetime is made up of
Lots of short moments.
"Henry" <hs****@onproje ct.com> wrote in message
news:eT******** ******@TK2MSFTN GP04.phx.gbl...
I know it is possible to store dynamic propterties for applications in XML
files. The app.config and the web.config files can be used to store
AppSettings. .. I am just wondering how far one can go with this technique.
In my case, what I am interested in doing is to store information about
reports and report parameters that I might want to use in an XML file.
Ideally I'd like to get to the point answer and respond to the following
questins by reading a data file:
For a given report:
What are the parameters I need to pass to the report.
What are the parameter names?
What are the parameter data types?
What query should I issue to the database in order to retrieve the
possible values?
What type of Interface control, e.g. listbox, combobox, treeview, etc.,
should I use to display this information?
Given the specific Interface what data do I need to set to populate
that control? How do I associate a data column from the query to a
control property?
Perhaps even where on my query form should I place this control?
What report file will I be opening?
If I am pushing data to the report, what is the query or queries I used to
generate the DataSet?
The major question here is whether it is possible to build data controls
based on dynamic data read from a file? and if so, what is the strategy
for doing so?