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

persisting font info

P: n/a
Can anyone tell me how to persist and retrieve the font characteristics that
a user chooses to have displayed in a personalized label field on the front
of their application? I wanted to be able to give the user this ability so
that they could place a company logo, motto, or simply a message of the day
on the form, and have it redisplay from then on at start up just as it was to
begin with. I was trying to use an .rtf file to store the data. The place
I'm running into trouble is with the FontStyle. I can't reduplicate a
FontStyle of say, Bold/Italic/Underline. I can only reduplicate one of those
with a FontStyle fontstyle = FontStyle.Bold statement and then create a new
Font with a new Font(fontfamily, fontsize, fontstyle) statement. Any help
with this question would be greatly appreciated.
Jul 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
I dont quite understand why you are using .RTF to store the information. As
far as the FontStyle you can use OR because it supports bitmask. Ie. Font f =
new Font("Arial", 12F, FontStyle.Bold | FontStyle.Italic); Font is immutable
so you have to create a new object.

"Derrick" wrote:
Can anyone tell me how to persist and retrieve the font characteristics that
a user chooses to have displayed in a personalized label field on the front
of their application? I wanted to be able to give the user this ability so
that they could place a company logo, motto, or simply a message of the day
on the form, and have it redisplay from then on at start up just as it was to
begin with. I was trying to use an .rtf file to store the data. The place
I'm running into trouble is with the FontStyle. I can't reduplicate a
FontStyle of say, Bold/Italic/Underline. I can only reduplicate one of those
with a FontStyle fontstyle = FontStyle.Bold statement and then create a new
Font with a new Font(fontfamily, fontsize, fontstyle) statement. Any help
with this question would be greatly appreciated.

Jul 21 '05 #2

P: n/a
Thank you Alex. Can you suggest a better way of saving the font data? I
would really like to do this the best and most efficient way possible.

Cheers,
Derrick

"Alex Korchemniy" wrote:
I dont quite understand why you are using .RTF to store the information. As
far as the FontStyle you can use OR because it supports bitmask. Ie. Font f =
new Font("Arial", 12F, FontStyle.Bold | FontStyle.Italic); Font is immutable
so you have to create a new object.

"Derrick" wrote:
Can anyone tell me how to persist and retrieve the font characteristics that
a user chooses to have displayed in a personalized label field on the front
of their application? I wanted to be able to give the user this ability so
that they could place a company logo, motto, or simply a message of the day
on the form, and have it redisplay from then on at start up just as it was to
begin with. I was trying to use an .rtf file to store the data. The place
I'm running into trouble is with the FontStyle. I can't reduplicate a
FontStyle of say, Bold/Italic/Underline. I can only reduplicate one of those
with a FontStyle fontstyle = FontStyle.Bold statement and then create a new
Font with a new Font(fontfamily, fontsize, fontstyle) statement. Any help
with this question would be greatly appreciated.

Jul 21 '05 #3

P: n/a
RTF wasn't exactly intended for saving fonts. You have to go through a code
mess / hacks to get it to work. If I had to save some font data to disk I
would do it in an XML file.

Here's a piece of code for appsettings serializing:

using System;
using System.IO;
using System.Xml;

namespace Example
{
public class AppSettings
{
private XmlDocument xd = new XmlDocument();

public AppSettings()
{
string path = System.Windows.Forms.Application.StartupPath +
"\\appsettings.xml";
if (File.Exists(path))
xd.Load(path);
else
xd.LoadXml("<AppSettings></AppSettings>");
}

public string GetSetting(string settingPath)
{
try
{
string[] path = settingPath.Split(".".ToCharArray());
XmlElement current = xd.DocumentElement[path[0]];
for(int x = 1; x<path.Length; x++)
{
current = current[path[x]];
}
return current.InnerText;
}
catch
{
return "";
}
}
public void SetSetting(string settingPath, string val)
{
string[] path = settingPath.Split(".".ToCharArray());
XmlElement current;
if (xd.DocumentElement[path[0]] != null)
{
current = xd.DocumentElement[path[0]];
}
else
{
current = xd.CreateElement(path[0]);
xd.DocumentElement.AppendChild(current);
}
for(int x = 1; x<path.Length; x++)
{
if (current[path[x]] != null)
{
current = current[path[x]];
}
else
{
current.AppendChild(xd.CreateElement(path[x]));
current = current[path[x]];
}
}
current.InnerText = val;
return;
}
public void Save()
{
xd.Save(System.Windows.Forms.Application.StartupPa th +
"\\appsettings.xml");
}
}
}
"Derrick" wrote:
Thank you Alex. Can you suggest a better way of saving the font data? I
would really like to do this the best and most efficient way possible.

Cheers,
Derrick

"Alex Korchemniy" wrote:
I dont quite understand why you are using .RTF to store the information. As
far as the FontStyle you can use OR because it supports bitmask. Ie. Font f =
new Font("Arial", 12F, FontStyle.Bold | FontStyle.Italic); Font is immutable
so you have to create a new object.

"Derrick" wrote:
Can anyone tell me how to persist and retrieve the font characteristics that
a user chooses to have displayed in a personalized label field on the front
of their application? I wanted to be able to give the user this ability so
that they could place a company logo, motto, or simply a message of the day
on the form, and have it redisplay from then on at start up just as it was to
begin with. I was trying to use an .rtf file to store the data. The place
I'm running into trouble is with the FontStyle. I can't reduplicate a
FontStyle of say, Bold/Italic/Underline. I can only reduplicate one of those
with a FontStyle fontstyle = FontStyle.Bold statement and then create a new
Font with a new Font(fontfamily, fontsize, fontstyle) statement. Any help
with this question would be greatly appreciated.

Jul 21 '05 #4

P: n/a
Hi Derrick,

There are at least two ways of doing this:
1. Store values for each argument used in the font constructor and it's type
in a config file. Retrieve them and cast them as require while calling the
constructor
2. Serialize the font object store it in a file. Deserialize the data when
required.

Let me know if you need more info.

HTH,
Rakesh Rajan

"Derrick" wrote:
Thank you Alex. Can you suggest a better way of saving the font data? I
would really like to do this the best and most efficient way possible.

Cheers,
Derrick

"Alex Korchemniy" wrote:
I dont quite understand why you are using .RTF to store the information. As
far as the FontStyle you can use OR because it supports bitmask. Ie. Font f =
new Font("Arial", 12F, FontStyle.Bold | FontStyle.Italic); Font is immutable
so you have to create a new object.

"Derrick" wrote:
Can anyone tell me how to persist and retrieve the font characteristics that
a user chooses to have displayed in a personalized label field on the front
of their application? I wanted to be able to give the user this ability so
that they could place a company logo, motto, or simply a message of the day
on the form, and have it redisplay from then on at start up just as it was to
begin with. I was trying to use an .rtf file to store the data. The place
I'm running into trouble is with the FontStyle. I can't reduplicate a
FontStyle of say, Bold/Italic/Underline. I can only reduplicate one of those
with a FontStyle fontstyle = FontStyle.Bold statement and then create a new
Font with a new Font(fontfamily, fontsize, fontstyle) statement. Any help
with this question would be greatly appreciated.

Jul 21 '05 #5

P: n/a
Thanks to the quick and thorough information you all gave I was able to do
what I wanted. I still have a lot of learning to do. I couldn't have done
it without your help. Thanks a ton!

Derrick

"Alex Korchemniy" wrote:
RTF wasn't exactly intended for saving fonts. You have to go through a code
mess / hacks to get it to work. If I had to save some font data to disk I
would do it in an XML file.

Here's a piece of code for appsettings serializing:

using System;
using System.IO;
using System.Xml;

namespace Example
{
public class AppSettings
{
private XmlDocument xd = new XmlDocument();

public AppSettings()
{
string path = System.Windows.Forms.Application.StartupPath +
"\\appsettings.xml";
if (File.Exists(path))
xd.Load(path);
else
xd.LoadXml("<AppSettings></AppSettings>");
}

public string GetSetting(string settingPath)
{
try
{
string[] path = settingPath.Split(".".ToCharArray());
XmlElement current = xd.DocumentElement[path[0]];
for(int x = 1; x<path.Length; x++)
{
current = current[path[x]];
}
return current.InnerText;
}
catch
{
return "";
}
}
public void SetSetting(string settingPath, string val)
{
string[] path = settingPath.Split(".".ToCharArray());
XmlElement current;
if (xd.DocumentElement[path[0]] != null)
{
current = xd.DocumentElement[path[0]];
}
else
{
current = xd.CreateElement(path[0]);
xd.DocumentElement.AppendChild(current);
}
for(int x = 1; x<path.Length; x++)
{
if (current[path[x]] != null)
{
current = current[path[x]];
}
else
{
current.AppendChild(xd.CreateElement(path[x]));
current = current[path[x]];
}
}
current.InnerText = val;
return;
}
public void Save()
{
xd.Save(System.Windows.Forms.Application.StartupPa th +
"\\appsettings.xml");
}
}
}
"Derrick" wrote:
Thank you Alex. Can you suggest a better way of saving the font data? I
would really like to do this the best and most efficient way possible.

Cheers,
Derrick

"Alex Korchemniy" wrote:
I dont quite understand why you are using .RTF to store the information. As
far as the FontStyle you can use OR because it supports bitmask. Ie. Font f =
new Font("Arial", 12F, FontStyle.Bold | FontStyle.Italic); Font is immutable
so you have to create a new object.

"Derrick" wrote:

> Can anyone tell me how to persist and retrieve the font characteristics that
> a user chooses to have displayed in a personalized label field on the front
> of their application? I wanted to be able to give the user this ability so
> that they could place a company logo, motto, or simply a message of the day
> on the form, and have it redisplay from then on at start up just as it was to
> begin with. I was trying to use an .rtf file to store the data. The place
> I'm running into trouble is with the FontStyle. I can't reduplicate a
> FontStyle of say, Bold/Italic/Underline. I can only reduplicate one of those
> with a FontStyle fontstyle = FontStyle.Bold statement and then create a new
> Font with a new Font(fontfamily, fontsize, fontstyle) statement. Any help
> with this question would be greatly appreciated.
>
>

Jul 21 '05 #6

P: n/a
Serializing sounds like a good way to go. Especially since the FontStyle has
no constructor. I'll need to spend some time researching how to do it this
way. The way I've been able to do so far is quite hacky. Thank you for the
great tip.

Derrick

"Rakesh Rajan" wrote:
Hi Derrick,

There are at least two ways of doing this:
1. Store values for each argument used in the font constructor and it's type
in a config file. Retrieve them and cast them as require while calling the
constructor
2. Serialize the font object store it in a file. Deserialize the data when
required.

Let me know if you need more info.

HTH,
Rakesh Rajan

"Derrick" wrote:
Thank you Alex. Can you suggest a better way of saving the font data? I
would really like to do this the best and most efficient way possible.

Cheers,
Derrick

"Alex Korchemniy" wrote:
I dont quite understand why you are using .RTF to store the information. As
far as the FontStyle you can use OR because it supports bitmask. Ie. Font f =
new Font("Arial", 12F, FontStyle.Bold | FontStyle.Italic); Font is immutable
so you have to create a new object.

"Derrick" wrote:

> Can anyone tell me how to persist and retrieve the font characteristics that
> a user chooses to have displayed in a personalized label field on the front
> of their application? I wanted to be able to give the user this ability so
> that they could place a company logo, motto, or simply a message of the day
> on the form, and have it redisplay from then on at start up just as it was to
> begin with. I was trying to use an .rtf file to store the data. The place
> I'm running into trouble is with the FontStyle. I can't reduplicate a
> FontStyle of say, Bold/Italic/Underline. I can only reduplicate one of those
> with a FontStyle fontstyle = FontStyle.Bold statement and then create a new
> Font with a new Font(fontfamily, fontsize, fontstyle) statement. Any help
> with this question would be greatly appreciated.
>
>

Jul 21 '05 #7

P: n/a
Hi Derrick,

Glad to know that :)

Just in case you need the MSDN link to serialization concepts
http://msdn.microsoft.com/library/en...ialization.asp

Regards,
Rakesh Rajan

"Derrick" wrote:
Serializing sounds like a good way to go. Especially since the FontStyle has
no constructor. I'll need to spend some time researching how to do it this
way. The way I've been able to do so far is quite hacky. Thank you for the
great tip.

Derrick

"Rakesh Rajan" wrote:
Hi Derrick,

There are at least two ways of doing this:
1. Store values for each argument used in the font constructor and it's type
in a config file. Retrieve them and cast them as require while calling the
constructor
2. Serialize the font object store it in a file. Deserialize the data when
required.

Let me know if you need more info.

HTH,
Rakesh Rajan

"Derrick" wrote:
Thank you Alex. Can you suggest a better way of saving the font data? I
would really like to do this the best and most efficient way possible.

Cheers,
Derrick

"Alex Korchemniy" wrote:

> I dont quite understand why you are using .RTF to store the information. As
> far as the FontStyle you can use OR because it supports bitmask. Ie. Font f =
> new Font("Arial", 12F, FontStyle.Bold | FontStyle.Italic); Font is immutable
> so you have to create a new object.
>
> "Derrick" wrote:
>
> > Can anyone tell me how to persist and retrieve the font characteristics that
> > a user chooses to have displayed in a personalized label field on the front
> > of their application? I wanted to be able to give the user this ability so
> > that they could place a company logo, motto, or simply a message of the day
> > on the form, and have it redisplay from then on at start up just as it was to
> > begin with. I was trying to use an .rtf file to store the data. The place
> > I'm running into trouble is with the FontStyle. I can't reduplicate a
> > FontStyle of say, Bold/Italic/Underline. I can only reduplicate one of those
> > with a FontStyle fontstyle = FontStyle.Bold statement and then create a new
> > Font with a new Font(fontfamily, fontsize, fontstyle) statement. Any help
> > with this question would be greatly appreciated.
> >
> >

Jul 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.