Click here to Skip to main content
15,899,754 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Load Text file into a RichTextBox Pin
Dave Kreskowiak21-Jun-04 8:55
mveDave Kreskowiak21-Jun-04 8:55 
GeneralRe: Load Text file into a RichTextBox Pin
Brad Fackrell21-Jun-04 9:26
Brad Fackrell21-Jun-04 9:26 
GeneralRe: Load Text file into a RichTextBox Pin
Dave Kreskowiak21-Jun-04 9:30
mveDave Kreskowiak21-Jun-04 9:30 
GeneralRe: Load Text file into a RichTextBox Pin
Brad Fackrell21-Jun-04 9:34
Brad Fackrell21-Jun-04 9:34 
GeneralThumbnail in ListView Pin
Brad Fackrell21-Jun-04 5:41
Brad Fackrell21-Jun-04 5:41 
GeneralRe: Thumbnail in ListView Pin
Dave Kreskowiak21-Jun-04 5:56
mveDave Kreskowiak21-Jun-04 5:56 
GeneralHelp needed to serialize Controls using XML in VB.NET Pin
realminds21-Jun-04 1:53
realminds21-Jun-04 1:53 
GeneralRe: Help needed to serialize Controls using XML in VB.NET Pin
pvoicu21-Jun-04 3:10
pvoicu21-Jun-04 3:10 
Try something like this (the code is in C# but you'll get the ideea):

Declare a typed dataset -WorkspaceDataset- within your project, having a table for storing controls bounds, called Controls; the columns used to reposition and resize each and every control would be Top, Left, Width, Height.
Any other properties you would like to store- add them as columns. I guess you could have a table for each control type.
If you want to get really flexible, you could use Reflection and discover the properties for each of the control types, create the dataset dynamically according to each property type and do the same when retrieving their values.
The following is just a simple example, only for the bounds of the controls.

<xs:element name="Controls" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType>
<xs:sequence>
<xs:element name="IDControl" type="xs:ID" minOccurs="0" msdata:AutoIncrement="true" msdata:AutoIncrementSeed="-1" msdata:AutoIncrementStep="-1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="ParentControl" type="xs:string" minOccurs="0" />
<xs:element name="Top" type="xs:int" minOccurs="0" />
<xs:element name="Left" type="xs:int" minOccurs="0" />
<xs:element name="Height" type="xs:int" minOccurs="0" />
<xs:element name="Width" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

//In the form that you want to serialize/deserialize, declare a dataset member from the above type

private WorkspaceDataset workspaceDataset = new WorkspaceDataset();

//read the dataset from a xml file
private void deserializeControls(string xmlFilename)
{
this.workspaceDataset.Clear();
try
{
this.workspaceDataset.ReadXml(xmlFilename);
//call this function for the form, which, in turn will call itself recursively for each of the children controls
this.deserializeControl(this);
}
catch(Exception e)
{
MessageBox.Show(e.Message + "\n\n" + e.StackTrace);
}
}

//reads the control bounds from the dataset, by the Name property of the control
private void deserializeControl(System.Windows.Forms.Control control)
{
try
{//retrieve only controls that are named, it will not work for datagrid columns and other controls that are not named
if(control.Name != null)
{
if(control.Name != "")
{//read the bounds of the control from the datasets' Controls table
DataRow[] ctls = this.workspaceDataset.Controls.Select(
"Name = '" + control.Name + "'");
if(ctls.Length > 0)
{
ControlsRow controlRow = (ControlsRow)ctls[0];
//set the bounds of the control
control.SetBounds(
controlRow.Left,
controlRow.Top,
controlRow.Width,
controlRow.Height);
}
}
}

//call the same function recursively for all the children of the current control
foreach(System.Windows.Forms.Control child in control.Controls)
{
this.deserializeControl(child);
}
}
catch(Exception e)
{
MessageBox.Show(e.Message + "\n\n" + e.StackTrace);
}

}

//serialize the controls bounds into a xml file
private void serializeControls(string xmlFilename)
{
//clear the current values that were retreived when deserializing and start from scratch
this.workspaceDataset.Clear();
//call this function for the form, which, in turn will call itself recursively for each of the children controls
this.serializeControl(this);
this.workspaceDataset.WriteXml(xmlFilename);
}

//store the bounds of the current control and calls itself recursively for all the control's children
private void serializeControl(System.Windows.Forms.Control control)
{
if(control.Name != null)
{
if(control.Name != "")
{
ControlsRow controlRow =
this.workspaceDataset.Controls.NewControlsRow();
controlRow.Name = control.Name;
if(control.Parent != null)
{
controlRow.ParentControl = control.Parent.Name;
}
controlRow.Top = control.Top;
controlRow.Left = control.Left;
controlRow.Height = control.Height;
controlRow.Width = control.Width;
this.workspaceDataset.Controls.AddControlsRow(controlRow);
}
}

//call itself recursively for all the children
foreach(System.Windows.Forms.Control child in control.Controls)
{
this.serializeControl(child);
}
}

I hope this will help. I know there is the XmlSerialization but I didn't really care about all the properties myself, just the bounds, and this one worked fine for me.
GeneralRe: Help needed to serialize Controls using XML in VB.NET Pin
pvoicu21-Jun-04 3:20
pvoicu21-Jun-04 3:20 
Generaldatagrid to txt file Pin
Brakanjan20-Jun-04 23:57
Brakanjan20-Jun-04 23:57 
GeneralRe: datagrid to txt file Pin
Dave Kreskowiak21-Jun-04 3:54
mveDave Kreskowiak21-Jun-04 3:54 
GeneralCreation of Setup.exe, Myprogram.cab file using VB.NET Pin
manishthouri20-Jun-04 21:49
manishthouri20-Jun-04 21:49 
GeneralRe: Creation of Setup.exe, Myprogram.cab file using VB.NET Pin
Dave Kreskowiak21-Jun-04 3:51
mveDave Kreskowiak21-Jun-04 3:51 
GeneralRe: Access of data contained within an excel sheet which has been opened within a web browser control in a VB.NET windows form Pin
Dave Kreskowiak21-Jun-04 3:37
mveDave Kreskowiak21-Jun-04 3:37 
GeneralRe: Access of data contained within an excel sheet which has been opened within a web browser control in a VB.NET windows form Pin
vijaykri21-Jun-04 19:48
vijaykri21-Jun-04 19:48 
GeneralRe: Access of data contained within an excel sheet which has been opened within a web browser control in a VB.NET windows form Pin
Dave Kreskowiak22-Jun-04 1:40
mveDave Kreskowiak22-Jun-04 1:40 
GeneralRe: Access of data contained within an excel sheet which has been opened within a web browser control in a VB.NET windows form Pin
vijaykri22-Jun-04 1:58
vijaykri22-Jun-04 1:58 
Generalseek example code for pocket pc mp3 player / voice recorder Pin
softy7220-Jun-04 17:48
softy7220-Jun-04 17:48 
GeneralRe: seek example code for pocket pc mp3 player / voice recorder Pin
Dave Kreskowiak21-Jun-04 3:43
mveDave Kreskowiak21-Jun-04 3:43 
QuestionHow to turn XML file into Database Pin
neuaspx20-Jun-04 14:16
neuaspx20-Jun-04 14:16 
AnswerRe: How to turn XML file into Database Pin
Dave Kreskowiak21-Jun-04 3:24
mveDave Kreskowiak21-Jun-04 3:24 
GeneralFile to TreeView Problem Pin
bigmutty20-Jun-04 10:28
bigmutty20-Jun-04 10:28 
Generalmysterious compile error Pin
MGEMM20-Jun-04 7:22
MGEMM20-Jun-04 7:22 
QuestionHow to stop process before end? Pin
shinay19-Jun-04 19:39
shinay19-Jun-04 19:39 
AnswerRe: How to stop process before end? Pin
Dave Kreskowiak21-Jun-04 3:09
mveDave Kreskowiak21-Jun-04 3:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.