Having a bit of fun here. I've read in a file in XML and deseralised it. Based on the contents of the XML file, I've generated a page on the fly (and it works).
However, the XML file contains the data for more than one page to be generated. The idea is that you click the forward button, the event is fired and the new window generated.
The deserialiser method passes the XML data to the winform generator directly which is then passed to the button click.
The problem is this. I can't get it to move to the next set of data!
Current code looks like this
(nothing of any real interest happens after this point, just display the window)
The click event looks like this
It is in the same class as the form generator. The XML reader is in a completely different class (has to be for other reasons).
There is nothing special about how the XML stuff is set up
The Elements class defines a pile of attributes and the instantates Elements with them.
int page is pretty much ignored but needs to be used but I'm not sure how to. Any help would be appreciated.
Paul
However, the XML file contains the data for more than one page to be generated. The idea is that you click the forward button, the event is fired and the new window generated.
The deserialiser method passes the XML data to the winform generator directly which is then passed to the button click.
The problem is this. I can't get it to move to the next set of data!
Current code looks like this
Code:
namespace form_from_xml { public class xmlhandler : Form { public void loaddesign() { FormData f; f = null; try { string path_env = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar; XmlSerializer s = new XmlSerializer(typeof(FormData)); TextReader r = new StreamReader(path_env + "designer-test.xml"); f = (FormData)s.Deserialize(r); r.Close(); } catch (System.IO.FileNotFoundException) { MessageBox.Show("Unable to find the form file", "File not found", MessageBoxButtons.OK); } catch (System.InvalidOperationException e) { MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK); } winformgen wf = new winformgen(); wf.makeform(f, 1); } } public class winformgen : Form { public void makeform(FormData f, int page) { Form form1 = new Form(); Assembly asm = typeof(Form).Assembly; foreach (Elements fort in f.elements) { System.Type tp = asm.GetType(fort.type); Object m = Activator.CreateInstance(tp); if (m is Control) { Control widget = (Control)m; if (fort.forwardlink != 999 || fort.backlink != 999) { Button b = new Button(); if (fort.forwardlink != 999) { b.Name = "forward"; b.Location = new Point(fort.winxs - 100, fort.winys - 75); b.Text = "Next >>"; } else { b.Name = "backward"; b.Location = new Point(fort.winxs - 200, fort.winys - 575); b.Text = "<< Back"; } b.Height = 23; b.Width = 75; form1.Controls.Add(b); b.Click += delegate(object s, EventArgs e) { ButtonClick(s, e, f, fort.pagenumber); }; }
The click event looks like this
Code:
private void ButtonClick(object o, EventArgs e, FormData f, int page) { Control m = (Button)o; if (m.Name == "forward") makeform(f, f.elements[page].forwardlink); else makeform(f, f.elements[page].backlink); }
There is nothing special about how the XML stuff is set up
Code:
[XmlRoot("Forms")] public class FormData { private ArrayList formData; public FormData() { formData = new ArrayList(); } [XmlElement("Element")] public Elements[] elements { get { Elements[] elements = new Elements[formData.Count]; formData.CopyTo(elements); return elements; } set { if (value == null) return; Elements[] elements = (Elements[])value; formData.Clear(); foreach (Elements element in elements) formData.Add(element); } } public int AddItem(Elements element) { return formData.Add(element); } } public class Elements { [XmlAttribute("formname")] public string fname; [XmlAttribute("winxsize")] public int winxs;
int page is pretty much ignored but needs to be used but I'm not sure how to. Any help would be appreciated.
Paul
Comment