hi,
i want to know how can i save user control like textbox (i want to save the textbox as a control user not the value of the contorl )
in a xml file and when i press button named load from xml file
he load the textbox on the from (ie. create the textbox)
please any one help me
thanks,

save control user to xml file
Meaning Of Lights
Hi sir:
I have create a demo for adding controls in form load event as follows;
for (int i = 0; i <= 3; i++)
{
TextBox TB = new TextBox();
TB.Location = new System.Drawing.Point(42, 20*i);
TB.Name = "textBox"+i.ToString();
TB.Size = new System.Drawing.Size(80, 20);
TB.TabIndex = i;
this.Controls.Add(TB);
}
and if you want using xml , we can store controls name in xml files, I can continue to create some xml reading code,
if you need,
Best Regards!
abousoft
yes please help me
i want to know how to save it in xml file
Miles100
yes I think we can add object than convert object to controls as we defined in XML file;
I still use the old XML , as I think we can easily read "System.Windows.Forms.Button" as some control type
hope it help you
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Collections;
using System.Reflection;
namespace WindowsApplication2
{
public partial class Form8 : Form
{
public Form8()
{
InitializeComponent();
}
private void Form8_Load(object sender, EventArgs e)
{
string path = Environment.CurrentDirectory;
path += "\\XMLFile1.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNodeReader reader = new XmlNodeReader(doc);
ArrayList al = new ArrayList();
string s="";
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
s = reader.Name;
break;
case XmlNodeType.Text:
if (s.Equals("Name"))
al.Add(reader.Value);
break;
}
}
for (int i = 0; i < al.Count; i++)
{
string a="System.Windows.Forms.Button";
System.Reflection.Assembly ASS = Assembly.GetAssembly(typeof(Form));
Type t = ASS.GetType(a);
Object control = Activator.CreateInstance(t);
Control bt = (Control)control;
this.Controls.Add(bt);
bt.Location = new System.Drawing.Point(42, 20 * i);
bt.Name = "textBox" + i.ToString();
bt.Size = new System.Drawing.Size(80, 20);
bt.Text = al
.ToString();
bt.TabIndex = i;
this.Controls.Add(bt);
}
}
}
TiborK
please can you make small demo code
to tell me how can i use xmltextwriter to save control proprity to xml file to make some thing like this
<controls>
<control type="System.Windows.Forms.Button">
<position>
<height>23</height>
<width>75</width>
<top>144</top>
<left>160</left>
</position>
<controls />
<name>button2</name>
<text>button2</text>
<tabIndex>2</tabIndex>
<event-handlers />
please help me
kenneth123
You can't do it that way.
The easiest way is to just store also the textbox's attributes/properties that you want to set during creation in the XML file.
HbH
you can try as my demo shows, just store some properity in the xml file;
such as control's name, location, and read those properity when you want to load those controls:)
Best Regards!
WhitebearJPN
thank you
but what i want is how to load the creiation code from xml file
i mean that xml structur is contain the code of creiation
and when i press button nammed (load from xml file)
it create atext box
Deepak Goyal
Praveen Dayanithi
LegendRey
an easy demo hope help you
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Collections;
namespace WindowsApplication2
{
public partial class Form8 : Form
{
public Form8()
{
InitializeComponent();
}
private void Form8_Load(object sender, EventArgs e)
{
string path = Environment.CurrentDirectory;
path += "\\XMLFile1.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNodeReader reader = new XmlNodeReader(doc);
ArrayList al = new ArrayList();
string s="";
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
s = reader.Name;
break;
case XmlNodeType.Text:
if (s.Equals("Name"))
al.Add(reader.Value);
break;
}
}
for (int i = 0; i < al.Count; i++)
{
TextBox TB = new TextBox();
TB.Location = new System.Drawing.Point(42, 20 * i);
TB.Name = "textBox" + i.ToString();
TB.Size = new System.Drawing.Size(80, 20);
TB.Text = al
.ToString();
TB.TabIndex = i;
this.Controls.Add(TB);
}
}
}
}
< xml version="1.0" encoding="utf-8" >
<Employees>
<NO1>
<Name>May</Name>
</NO1>
<NO2>
<Name>July</Name>
</NO2>
<NO3>
<Name>Any</Name>
</NO3>
</Employees>