473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Serializing and deserializing form layout

Hi all

Is there a way to serialize the current form's layout to a string or file?

I'll re-phrase - is there an EASY way to do it ;-)

Thanks
Kev
Jun 6 '06 #1
4 1629
Mantorok wrote:
Is there a way to serialize the current form's layout to a string or file?

Kev,

I'm not sure if this will accomplish what you want to do, but code for
the controls and layout of the form will be in the
InitializeComponents() method generated by the IDE (assuming you used
the IDE to make the form). If so, you may be able to use reflection to
look at the contents of that method.

Dan Manges
Jun 6 '06 #2
Dan Manges wrote:
I'm not sure if this will accomplish what you want to do, but code for
the controls and layout of the form will be in the
InitializeComponents() method generated by the IDE (assuming you used
the IDE to make the form). If so, you may be able to use reflection to
look at the contents of that method.


If you know what the controls on your form are, an easier solution would
be to just write a method to look at each control's location and
serialize it however you want (e.g. "(0,0,20,30)" for top coordinates
and then size).

Maybe you could give more clarification as to what specifically you
would like to accomplish?

Thanks,

Dan Manges
Jun 6 '06 #3

"Dan Manges" <da***********@gmail.com> wrote in message
news:xf******************@tornado.ohiordc.rr.com.. .
Dan Manges wrote:
I'm not sure if this will accomplish what you want to do, but code for
the controls and layout of the form will be in the InitializeComponents()
method generated by the IDE (assuming you used the IDE to make the form).
If so, you may be able to use reflection to look at the contents of that
method.


If you know what the controls on your form are, an easier solution would
be to just write a method to look at each control's location and serialize
it however you want (e.g. "(0,0,20,30)" for top coordinates and then
size).

Maybe you could give more clarification as to what specifically you would
like to accomplish?


I basically have a base-class form and when the form closes and loads I want
it to serialise/deserialize the layout (where possible). My main interests
are size of control.

I would prefer it if the form handled this so that I don't have to code it
for each new control I create.

Kev
Jun 7 '06 #4
Mantorok wrote:
I basically have a base-class form and when the form closes and loads I want
it to serialise/deserialize the layout (where possible). My main interests
are size of control.

I would prefer it if the form handled this so that I don't have to code it
for each new control I create.

Kev


Ah, so you're talking about the size and location of just the form?
(Sorry for the really bad advice before, I misunderstood what you were
trying to do).

I would either use a base class to do this for all your forms, or use a
static method in a helper class that takes the form as an argument.

Example using a static method (can easily be adjusted to use a base class):

public static void RememberFormSize(Form myForm)
{
/* load height and width from where you saved it last and adjust
the form accordingly */
myForm.Resize += new EventHandler(myForm_Resize);
}

static void myForm_Resize(object sender, EventArgs e)
{
Form theForm = (Form)sender;
int height = theForm.Size.Height;
int width = theForm.Size.Width;
/* save height and width in a file, database, or whatever works for
your application */
}

I think typecasting the sender in the myForm_Resize method to a Form
should be okay. Somebody please correct me if it's not.

Hopefully this helps you, sorry again for the bad advice before.

Dan Manges
Jun 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
5
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e....
2
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string...
7
by: fjlaga | last post by:
I have written an Office Add-in for Excel using VB.NET and the .NET 1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I want to add a User Settings/Prefereneces dialog and allow...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.