473,698 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

persisting font info

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
7 1688
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.Itali c); 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
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.Itali c); 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
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.Applicati on.StartupPath +
"\\appsettings. xml";
if (File.Exists(pa th))
xd.Load(path);
else
xd.LoadXml("<Ap pSettings></AppSettings>");
}

public string GetSetting(stri ng settingPath)
{
try
{
string[] path = settingPath.Spl it(".".ToCharAr ray());
XmlElement current = xd.DocumentElem ent[path[0]];
for(int x = 1; x<path.Length; x++)
{
current = current[path[x]];
}
return current.InnerTe xt;
}
catch
{
return "";
}
}
public void SetSetting(stri ng settingPath, string val)
{
string[] path = settingPath.Spl it(".".ToCharAr ray());
XmlElement current;
if (xd.DocumentEle ment[path[0]] != null)
{
current = xd.DocumentElem ent[path[0]];
}
else
{
current = xd.CreateElemen t(path[0]);
xd.DocumentElem ent.AppendChild (current);
}
for(int x = 1; x<path.Length; x++)
{
if (current[path[x]] != null)
{
current = current[path[x]];
}
else
{
current.AppendC hild(xd.CreateE lement(path[x]));
current = current[path[x]];
}
}
current.InnerTe xt = val;
return;
}
public void Save()
{
xd.Save(System. Windows.Forms.A pplication.Star tupPath +
"\\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.Itali c); 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
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.Itali c); 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
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.Applicati on.StartupPath +
"\\appsettings. xml";
if (File.Exists(pa th))
xd.Load(path);
else
xd.LoadXml("<Ap pSettings></AppSettings>");
}

public string GetSetting(stri ng settingPath)
{
try
{
string[] path = settingPath.Spl it(".".ToCharAr ray());
XmlElement current = xd.DocumentElem ent[path[0]];
for(int x = 1; x<path.Length; x++)
{
current = current[path[x]];
}
return current.InnerTe xt;
}
catch
{
return "";
}
}
public void SetSetting(stri ng settingPath, string val)
{
string[] path = settingPath.Spl it(".".ToCharAr ray());
XmlElement current;
if (xd.DocumentEle ment[path[0]] != null)
{
current = xd.DocumentElem ent[path[0]];
}
else
{
current = xd.CreateElemen t(path[0]);
xd.DocumentElem ent.AppendChild (current);
}
for(int x = 1; x<path.Length; x++)
{
if (current[path[x]] != null)
{
current = current[path[x]];
}
else
{
current.AppendC hild(xd.CreateE lement(path[x]));
current = current[path[x]];
}
}
current.InnerTe xt = val;
return;
}
public void Save()
{
xd.Save(System. Windows.Forms.A pplication.Star tupPath +
"\\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.Itali c); 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
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.Itali c); 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
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.Itali c); 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3083
by: Citoyen du Monde | last post by:
Trying to get some ideas on a simple javascript project (to teach myself the language). I want to develop a client-side vocabulary practice application that would allow users to enter their own words, their own definitions plus an example of how the word is used in practice. It'll be all client side with - cookies? to get persistence so that the words won't disappear on me each time the page is closed (which is what happened when I
39
8658
by: David Jubinville | last post by:
Hi All, I've run into a bit of an interesting problem with CSS and font DPI and would certainly welcome help. Problem: Page layout defined in CSS has font size issues (overlapping frames, text overflowing out of popup window, etc) on a windows systems using 120dpi fonts (large fonts), but everything looks perfect in 96dpi small fonts.
1
2285
by: Philip K | last post by:
I was trying to use Soap serialisation to save some systems settings how ever it fails if the settings contain a Font object, works fine if the Font object is not in the object being serialised. Font is marked in the MS documentation. Exception has been thrown by the target of an invocation. at System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)
2
2442
by: Lee Wilkie | last post by:
Dear All, I'm new to ASP.NET and have been developing a small app at work to test Forms Authentication. When running on my development machine (using http://localhost/TestApp/Login.aspx for example) everything works fine - that is, a successful (authenticated) login grants access to other app pages and the authorization cookie is saved as expected on the local machine. Unfortunately everything turns ugly when trying to 'test' the app...
1
1662
by: lim | last post by:
What is the possible error that occurs when the Page_load event is not triggered during execution. In my page there's some basic server control. Is there any loops holes?
3
1105
by: David Pendleton | last post by:
Hello all. Does anyone know how to persist or serialize a Font object? Possible? Thanks.
7
259
by: Derrick | last post by:
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...
2
3272
by: xenophon | last post by:
I added a Hidden Form Field to a form in the code behind. The value is being set in JavaScript client-side, but it is not persisting to the server in the PostBack. I know the value is being set properly because it displays in the document.write method. Create a simple page and paste the below in the code-behind (ASP.NET 1.1-SP1) using System;
5
4835
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7729
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.