PC Review


Reply
Thread Tools Rate Thread

Saving and retrieving WinForm template info

 
 
John
Guest
Posts: n/a
 
      2nd Jun 2009
Hi

Is there a way to save the following info about controls on a winform to a
named file and then retrieve them back when needed?

Control Name, Position on form, Control Binding Info

The idea is to have different layouts of the controls on the form for
different users and load appropriate layout/template for a user from file
when needed.

Thanks

Regards


 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      2nd Jun 2009
John,

Yes with a lot of work and probably very bad maintainable.

But you can use for that (in sequence of my preference) the registry, an
isolated storage, an XML file, a CSV file, a INI file maybe even more.

Cor

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> Is there a way to save the following info about controls on a winform to a
> named file and then retrieve them back when needed?
>
> Control Name, Position on form, Control Binding Info
>
> The idea is to have different layouts of the controls on the form for
> different users and load appropriate layout/template for a user from file
> when needed.
>
> Thanks
>
> Regards
>


 
Reply With Quote
 
 
 
 
Jesse Houwing
Guest
Posts: n/a
 
      2nd Jun 2009
Hello Cor Ligthert[MVP],

> John,
>
> Yes with a lot of work and probably very bad maintainable.
>
> But you can use for that (in sequence of my preference) the registry,
> an isolated storage, an XML file, a CSV file, a INI file maybe even
> more.


The Settings object comes to mind... it even has properties to store information
on a per user basis and can be used to databind their respective values to
the controls.

Probably the least amount of work.


> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> Hi
>>
>> Is there a way to save the following info about controls on a winform
>> to a named file and then retrieve them back when needed?
>>
>> Control Name, Position on form, Control Binding Info
>>
>> The idea is to have different layouts of the controls on the form for
>> different users and load appropriate layout/template for a user from
>> file when needed.
>>
>> Thanks
>>
>> Regards
>>

--
Jesse Houwing
jesse.houwing at sogeti.nl


 
Reply With Quote
 
James Hahn
Guest
Posts: n/a
 
      7th Jun 2009
If you can save the relevant control information in a list of strings you
can persist it into a string array in user settings. The control name
should not be saved, as you really need the control to exist before updating
it with the specific user information recovered from Settings, therefore
names should be generated according to an internal rule. I just use a
simple sequential form - User Panel 1, User Panel 2, etc.

Note that I am assuming you are dealing with one control type - it may be
possible with different control types, but a lot more complex. I can
therefore put each control in an array of controls (I have used A() in this
example) instead of referring to them through Me.Controls(). This means I
can access the controls by array index in A(), so I don't need to know the
names, and it means that there is no problem dealing with a variable number
of controls. My control is actually a user control (UserPanel) that
consists of a number of standard controls.

Set up your Settings storage like this - one for each property you need to
save.

User Setting Name - whatever (eg PANELTOPS)
User Setting Type - System.Collections.SpecializedStringCollection
User Setting Scope - User
User Setting Value -
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>25</string>
</ArrayOfString>

(25 is the actual default setting - change to your required default for each
particular list)

Then access it using code like the following:
'At Class level
Dim a As New List(Of UserPanel) 'Array of user panels.

'To save the Top of each control on a form:
Dim sp As New System.Collections.Specialized.StringCollection()
For N As Integer = 0 To A.Count - 1
sp.Add(A.(N).Location.Y.Tostring)
Next
My.Settings.PANELTOPS = sp
For N As Integer = 0 To A.Count - 1
sp.Add(A.(N).Location.X.Tostring)
Next
My.Settings.PANELLEFTS = sp
'etc
My.Settings.Save()

'To Retrieve and set the location of each control on a form
Dim UP as New UserPanel
Dim sp As New System.Collections.Specialized.StringCollection()
sp = My.Settings.PANELTOPS
For N As Integer = 0 To My.Settings.PANELTOPS.Count- 1
me.Controls.Add(UP)
a.add(UP)
'Other initialisation code for UP goes here
a(N).Location.Y = Val(sp(N))
Next
For N As Integer = 0 To My.Settings.PANELLEFTS.Count- 1
sp = My.Settings.PANELLEFTS
a(N).Location.X = Val(sp(N))
Next
'etc.

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> Is there a way to save the following info about controls on a winform to a
> named file and then retrieve them back when needed?
>
> Control Name, Position on form, Control Binding Info
>
> The idea is to have different layouts of the controls on the form for
> different users and load appropriate layout/template for a user from file
> when needed.
>
> Thanks
>
> Regards
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving and retrieving WinForm template info John Microsoft VB .NET 3 7th Jun 2009 02:10 AM
Retrieving Class, Function and Procedure name; retrieving line number Michel Vanderbeke Microsoft VB .NET 3 10th Aug 2007 07:19 PM
Retrieving Data: Speed of beating down rows vs retrieving from array? (PeteCresswell) Microsoft Excel Programming 2 9th Jul 2007 03:30 PM
saving info from laptop to cd and then completely deleting info from computer pam.aros@gmail.com Windows XP General 9 21st Apr 2007 09:28 PM
Winform>GUI>hide the frame in winform ? Tom Microsoft C# .NET 3 13th Sep 2004 02:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:31 PM.