By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,516 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

Controls layout save/load

P: n/a
Hi

Is there a way to save the layout of controls (position, size, visibility,
appearance etc.) to a file (xml?) and also be able to load the layout from a
file? The idea being that these file scan serve as templates for different
clients who may have different preferences.

Is someone has worked with this and can post some code examples then that
would be highly appreciated.

Thanks

Regards
Nov 21 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Hi,

http://windowsforms.net/articles/wfml.aspx

Ken
--------------
"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:Oh**************@tk2msftngp13.phx.gbl...
Hi

Is there a way to save the layout of controls (position, size, visibility,
appearance etc.) to a file (xml?) and also be able to load the layout from a
file? The idea being that these file scan serve as templates for different
clients who may have different preferences.

Is someone has worked with this and can post some code examples then that
would be highly appreciated.

Thanks

Regards

Nov 21 '05 #2

P: n/a
John,

When I saw your question I got this idea, (when you need the settings from
the form as well, you need to change it a little bit, however this shows
the idea in my opinion very well. It does all controls on a form even the
controls placed in a control.

It is tested and works.

\\\Needs just a form with some controls and one button to start the action.
Private ds As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Type")
dt.Columns.Add("Name")
dt.Columns.Add("Height")
dt.Columns.Add("Width")
dowrite(Me)
ds.WriteXml("c:\test1\MyControlSettings.xml")
End Sub
Private Sub dowrite(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
Dim dr As DataRow = ds.Tables(0).NewRow
dr("Type") = ctr.GetType.ToString
dr("Name") = ctr.Name
dr("Height") = ctr.Height
dr("Width") = ctr.Width
ds.Tables(0).Rows.Add(dr)
dowrite(ctr)
Next
End Sub
///

I hope this helps,

Cor
Nov 21 '05 #3

P: n/a
Wow!! I take it loading the file is as easy?

Thanks

Regards

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
John,

When I saw your question I got this idea, (when you need the settings from
the form as well, you need to change it a little bit, however this shows
the idea in my opinion very well. It does all controls on a form even the
controls placed in a control.

It is tested and works.

\\\Needs just a form with some controls and one button to start the
action.
Private ds As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Type")
dt.Columns.Add("Name")
dt.Columns.Add("Height")
dt.Columns.Add("Width")
dowrite(Me)
ds.WriteXml("c:\test1\MyControlSettings.xml")
End Sub
Private Sub dowrite(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
Dim dr As DataRow = ds.Tables(0).NewRow
dr("Type") = ctr.GetType.ToString
dr("Name") = ctr.Name
dr("Height") = ctr.Height
dr("Width") = ctr.Width
ds.Tables(0).Rows.Add(dr)
dowrite(ctr)
Next
End Sub
///

I hope this helps,

Cor

Nov 21 '05 #4

P: n/a
PS: Is it possible to run something like this as part of ide (macros)? Idea
being this displays all the forms in the project. User selects a name and
form layout is either saved. This is useful when creating templates for
shipping to clients.

Thanks again

Regards

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
John,

When I saw your question I got this idea, (when you need the settings from
the form as well, you need to change it a little bit, however this shows
the idea in my opinion very well. It does all controls on a form even the
controls placed in a control.

It is tested and works.

\\\Needs just a form with some controls and one button to start the
action.
Private ds As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Type")
dt.Columns.Add("Name")
dt.Columns.Add("Height")
dt.Columns.Add("Width")
dowrite(Me)
ds.WriteXml("c:\test1\MyControlSettings.xml")
End Sub
Private Sub dowrite(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
Dim dr As DataRow = ds.Tables(0).NewRow
dr("Type") = ctr.GetType.ToString
dr("Name") = ctr.Name
dr("Height") = ctr.Height
dr("Width") = ctr.Width
ds.Tables(0).Rows.Add(dr)
dowrite(ctr)
Next
End Sub
///

I hope this helps,

Cor

Nov 21 '05 #5

P: n/a
Is it possible to save all properties of controls without even knowing what
they are?

Thanks

Regards

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
John,

When I saw your question I got this idea, (when you need the settings from
the form as well, you need to change it a little bit, however this shows
the idea in my opinion very well. It does all controls on a form even the
controls placed in a control.

It is tested and works.

\\\Needs just a form with some controls and one button to start the
action.
Private ds As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Type")
dt.Columns.Add("Name")
dt.Columns.Add("Height")
dt.Columns.Add("Width")
dowrite(Me)
ds.WriteXml("c:\test1\MyControlSettings.xml")
End Sub
Private Sub dowrite(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
Dim dr As DataRow = ds.Tables(0).NewRow
dr("Type") = ctr.GetType.ToString
dr("Name") = ctr.Name
dr("Height") = ctr.Height
dr("Width") = ctr.Width
ds.Tables(0).Rows.Add(dr)
dowrite(ctr)
Next
End Sub
///

I hope this helps,

Cor

Nov 21 '05 #6

P: n/a
> Is it possible to save all properties of controls without even knowing
what they are?

Have you seen how many properties a control has,

I would not do that, height, width, left, top, color, font and maybe I
forget some is probably more than enough,

Cor
Nov 21 '05 #7

P: n/a
John,

In addition,

You have not have to save more than your program allows the user to change.

Cor
Nov 21 '05 #8

P: n/a
Thanks for that. How can I read the properties back? I guess the problem I
am facing is how to connect the read object's name with the object instance
on the form.

Thank again.

Regards

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OX*************@TK2MSFTNGP09.phx.gbl...
Is it possible to save all properties of controls without even knowing
what they are?

Have you seen how many properties a control has,

I would not do that, height, width, left, top, color, font and maybe I
forget some is probably more than enough,

Cor

Nov 21 '05 #9

P: n/a
John,

That should be easy now, however making the sample needed less words.

\\\Add to the same sample this. (and a button of course)
Private Sub Button2_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button2.Click
ds.ReadXml("c:\test1\myformsettings.xml")
ds.Tables(0).DefaultView.Sort = "Name"
DoRead(Me, ds.Tables(0).DefaultView)
End Sub

Public Sub DoRead(ByVal parentCtr As Control, _
ByVal dv As DataView)
Dim ctr As Control
For Each ctr In parentCtr.Controls
Dim i As Integer = dv.Find(ctr.Name)
ctr.Height = CInt(dv(i)("Height"))
ctr.Width = CInt(dv(i)("Width"))
DoRead(ctr, dv)
Next
End Sub
///
I hope this helps,

Cor
Nov 21 '05 #10

P: n/a
Hi,

I wroted Configuration Library with Layout Saver component (it's free, you
can download it with source code) whitch maby is what you are looking for.
http://www.habjansoftware.com/download.aspx (Configuration Library with
Layout Saver for .NET). Web page about this library is not yet finished, but
i can guide you thur it if you need (and you also have samples included in
zip).

Basicly what you need to do is to add component to Toolbox (right click on
toolbox->Add remove items->Browse to HS.Configuration.dll and open / import
it. You will see that 'LayoutSaver' component is added to toolbox.
Now you can drag&drop this component on any form you wish to save properties
you require.
When LayoutSaver component is added on form, you can select this form or any
control on it and press F4 to see PropertyGrid and look for property
'LSProperties on LayoutSaver1' and 'LSPropName on LayoutSaver1'..
When you click on 'LSProperties on LayoutSaver1' you will see dropdown
control with ability to select whitch propertyes for specified control you
want to save / restore (see Layout_In_Config_Sample or others).

I hope this helps ..

Regards,
Josip Habjan
URL: http://www.habjansoftware.com

"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:uP**************@TK2MSFTNGP14.phx.gbl...
Is it possible to save all properties of controls without even knowing
what they are?

Thanks

Regards

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
John,

When I saw your question I got this idea, (when you need the settings
from the form as well, you need to change it a little bit, however this
shows the idea in my opinion very well. It does all controls on a form
even the controls placed in a control.

It is tested and works.

\\\Needs just a form with some controls and one button to start the
action.
Private ds As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Type")
dt.Columns.Add("Name")
dt.Columns.Add("Height")
dt.Columns.Add("Width")
dowrite(Me)
ds.WriteXml("c:\test1\MyControlSettings.xml")
End Sub
Private Sub dowrite(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
Dim dr As DataRow = ds.Tables(0).NewRow
dr("Type") = ctr.GetType.ToString
dr("Name") = ctr.Name
dr("Height") = ctr.Height
dr("Width") = ctr.Width
ds.Tables(0).Rows.Add(dr)
dowrite(ctr)
Next
End Sub
///

I hope this helps,

Cor


Nov 21 '05 #11

P: n/a
Thanks for that Josip.

Sees like what I need. Any plans to make it work on vs2005?

Thanks

Regards

"Josip Habjan" <jh*****@spamoff-net.hr> wrote in message
news:d8**********@magcargo.vodatel.hr...
Hi,

I wroted Configuration Library with Layout Saver component (it's free, you
can download it with source code) whitch maby is what you are looking for.
http://www.habjansoftware.com/download.aspx (Configuration Library with
Layout Saver for .NET). Web page about this library is not yet finished,
but i can guide you thur it if you need (and you also have samples
included in zip).

Basicly what you need to do is to add component to Toolbox (right click on
toolbox->Add remove items->Browse to HS.Configuration.dll and open /
import it. You will see that 'LayoutSaver' component is added to toolbox.
Now you can drag&drop this component on any form you wish to save
properties you require.
When LayoutSaver component is added on form, you can select this form or
any control on it and press F4 to see PropertyGrid and look for property
'LSProperties on LayoutSaver1' and 'LSPropName on LayoutSaver1'..
When you click on 'LSProperties on LayoutSaver1' you will see dropdown
control with ability to select whitch propertyes for specified control you
want to save / restore (see Layout_In_Config_Sample or others).

I hope this helps ..

Regards,
Josip Habjan
URL: http://www.habjansoftware.com

"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:uP**************@TK2MSFTNGP14.phx.gbl...
Is it possible to save all properties of controls without even knowing
what they are?

Thanks

Regards

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
John,

When I saw your question I got this idea, (when you need the settings
from the form as well, you need to change it a little bit, however this
shows the idea in my opinion very well. It does all controls on a form
even the controls placed in a control.

It is tested and works.

\\\Needs just a form with some controls and one button to start the
action.
Private ds As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Type")
dt.Columns.Add("Name")
dt.Columns.Add("Height")
dt.Columns.Add("Width")
dowrite(Me)
ds.WriteXml("c:\test1\MyControlSettings.xml")
End Sub
Private Sub dowrite(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
Dim dr As DataRow = ds.Tables(0).NewRow
dr("Type") = ctr.GetType.ToString
dr("Name") = ctr.Name
dr("Height") = ctr.Height
dr("Width") = ctr.Width
ds.Tables(0).Rows.Add(dr)
dowrite(ctr)
Next
End Sub
///

I hope this helps,

Cor



Nov 21 '05 #12

P: n/a
You could use resource files (.resx).
"John" <Jo**@nospam.infovis.co.uk> skrev i melding
news:Oh**************@tk2msftngp13.phx.gbl...
Hi

Is there a way to save the layout of controls (position, size, visibility,
appearance etc.) to a file (xml?) and also be able to load the layout from
a file? The idea being that these file scan serve as templates for
different clients who may have different preferences.

Is someone has worked with this and can post some code examples then that
would be highly appreciated.

Thanks

Regards


Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.