Controls layout save/load

J

John

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
 
K

Ken Tucker [MVP]

Hi,

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

Ken
--------------
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
 
C

Cor Ligthert

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
 
J

John

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
 
J

John

Is it possible to save all properties of controls without even knowing what
they are?

Thanks

Regards
 
C

Cor Ligthert

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
 
C

Cor Ligthert

John,

In addition,

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

Cor
 
J

John

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
 
C

Cor Ligthert

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
 
J

Josip Habjan

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
 
J

John

Thanks for that Josip.

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

Thanks

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top