Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Fonts and colors with the registry (http://www.go4expert.com/forums/fonts-colors-registry-t4306/)

x64 15May2007 06:49

Fonts and colors with the registry
 
Hello again, I am nearing completion on my current project but I am stumped on reading and writing to the registry. I am using Francesco Natali's ModifyRegistry.cs from Code Project to help me do this. I have been successful in reading and writing int and string values but I am stuck on Fonts and Colors.

My main question is: What would I convert Fonts and Colors to, to write them into the registry? I have converted a font into a string to get it to write into the registry but I cannot read it as a string because "cannot convert from 'string' to 'System.Drawing.Font'" but I can convert a font to a string?

Thanks in advance for any help.

shabbir 15May2007 08:37

Re: Fonts and colors with the registry
 
Construct the font object with the font name as one of the parameter in constructor.

x64 16May2007 09:09

Re: Fonts and colors with the registry
 
That doesn't make since. If it gets written as a string to the registry, why can't I read it as a string? Or at least convert the string back to a Font. I can't add the name of the font in there, it will be different every time the user picks a different one. I am wanting to make it so what ever the user picks remains the default on start up.

shabbir 16May2007 10:12

Re: Fonts and colors with the registry
 
Basically if its written as string then its read as string. Now the string to font conversion is done through the constructor. You are not writing the Font object in registry or I am not sure if its possible as well.

x64 17May2007 04:54

Re: Fonts and colors with the registry
 
Ok well, I ran my program and I selected a simple font for it, here is what was put into the registry. [Font: Name=Wingdings 2, Size=8.25, Units=3, GdiCharSet=2, GdiVerticalFont=False] I used
Code:

private Font preffont;
 
public void WriteFormattingPrefsToRegistry()
{
reg.Write("font", GetFont());
}
 
public void ReadFormattingPrefsFromRegistry()
{
reg.BaseRegistryKey =
Registry.CurrentUser;
//This does not work with or without converting to a string.
SetFont(Convert.ToString(reg.Read("font")));
}
 


public
Font GetFont()
{
return preffont;
}
 
publicvoid SetFont(Font v)
{
preffont = v;
}

to write it to the registry, using a class with all the reg.write code. The Font object its self writes to the registry as a string automatically.
Quote:

Basically if its written as string then its read as string.
Thats what I was thinking as well, but I guess not.

shabbir 17May2007 08:04

Re: Fonts and colors with the registry
 
When you have written the font into the registry there will be an automatically string conversion but the vice versa is not true. Something like you always have a tostring but the reverse is not true for any object

x64 17May2007 08:28

Re: Fonts and colors with the registry
 
Alright thanks, I'll be sure to post a solution if I find out how to solve this problem.


All times are GMT +5.5. The time now is 20:58.