473,396 Members | 1,768 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,396 software developers and data experts.

Writing pens to file

Hi,

In my application I need to store pen objects in a file so they can be
read in at a latter stage from the file to recreate the pen objects in
memory. I'm currently doing this by hand, blindly writing out all the
properties of a pen like a donkey! Surely there must be a neat way in
..NET to read and write such objects? I don't want to simply serialize
the object as that would include a lot of stuff in the file I'm not
interested in. In the future I need to do a similar thing for brushes.

The code below shows how I write and read the compound array property
of a pen:

// Write pen's Compound array
int compLength = edgePens[i].CompoundArray.Length;
binaryWriter.Write(compLength);
for (int j = 0; j < compLength; j++)
{
binaryWriter.Write((double)edgePens[i].CompoundArray[j]);
}

// Read Pen's Compound array
int compLength = binaryReader.ReadInt32();
float compArray = new float[compLength]
for (int j = 0; j < compLength; j++)
{
compArray[j] = (float)binaryReader.ReadDouble()
}
Which as you can see, is a bit ugly when you have to do this kind of
thing for all the pen's properties!

Any help much appreciated.

Tristan.
Nov 15 '05 #1
1 1704
Hi Tristan,

I think that it's the only way of doing it, as the Pen class does not
support serialization ( nor you want it ).
I think that the best way of doing this, is saving only those properties
that you change in your code. I don't see other solution here :(

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tristan" <tr************@yahoo.co.uk> wrote in message
news:7f**************************@posting.google.c om...
Hi,

In my application I need to store pen objects in a file so they can be
read in at a latter stage from the file to recreate the pen objects in
memory. I'm currently doing this by hand, blindly writing out all the
properties of a pen like a donkey! Surely there must be a neat way in
.NET to read and write such objects? I don't want to simply serialize
the object as that would include a lot of stuff in the file I'm not
interested in. In the future I need to do a similar thing for brushes.

The code below shows how I write and read the compound array property
of a pen:

// Write pen's Compound array
int compLength = edgePens[i].CompoundArray.Length;
binaryWriter.Write(compLength);
for (int j = 0; j < compLength; j++)
{
binaryWriter.Write((double)edgePens[i].CompoundArray[j]);
}

// Read Pen's Compound array
int compLength = binaryReader.ReadInt32();
float compArray = new float[compLength]
for (int j = 0; j < compLength; j++)
{
compArray[j] = (float)binaryReader.ReadDouble()
}
Which as you can see, is a bit ugly when you have to do this kind of
thing for all the pen's properties!

Any help much appreciated.

Tristan.

Nov 15 '05 #2

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

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
2
by: Tristan | last post by:
Hi I'm trying to test if two Pen objects are equal as shown below Pen p1 = new Pen(Color.Black) Pen p2 = new Pen(Color.Black) if (p1.Equals(p2) Console.WriteLine("These pens equal")
3
by: ishekar | last post by:
Hi, I have an application where i want to write data to a file, the data is being sent from an external source. I know the total size of the data and then i retrieve the data in small segments...
0
by: Web Team | last post by:
Hi All, I'm trying to write web form that will be the source of an image tag, generating an image on the fly. e.g: <img src="genimage.aspx"> My code (in genimage.aspx) so far:
2
by: John | last post by:
I created a number of pictureboxes in a panel, and want to draw lines in those pictureboxes but I cannot. Please see the following code and make corrections. Thanks. Private Sub...
16
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
3
by: Barry Flynn | last post by:
Hi I am working with a VB 2005 program which has been converted from VB6. It writes data out to a flat file, with code like the following line WriteLine(riFileNo, "Hist", lsAssetID,...
9
by: raylopez99 | last post by:
Just an observation: pens for drawing lines in Win Forms are tricky when assignment is inside the paint handler. inside of the Paint handler, but not inside a "using" brace (that is, outside of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.