Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

this.fontDialog.Font=new Font((string)CommunicationLog.settings.GetValue("TitleFont.Name"),

(float)CommunicationLog.settings.GetValue("TitleFont.Size"),

(FontStyle)CommunicationLog.settings.GetValue("TitleFont.Style"));

 

That does not work, conversion error and it would be nice if I could save and load everything in one package. It can also be saved to the registry like this really easily but I cannot load it at all (it seems) this way:

 

[Font: Name=Bangle, Size=9.75, Units=3, GdiCharSet=0, GdiVerticalFont=False]

 

Help!

C#
Posted (edited)

public static FontStyle MakeStyle(object fontstyle)

{

char[]c={','};

string style=(string)fontstyle; style=style.Replace(" ", "");;

string[]Style=style.Split(c, 6);

FontStyle FS=new FontStyle();

for(int i=0; i<Style.Length; i++)

{

if(Style=="Bold") FS=FS^FontStyle.Bold;

if(Style=="Italic") FS=FS^FontStyle.Italic;

if(Style=="Italic") FS=FS^FontStyle.Italic;

if(Style=="Regular") FS=FS^FontStyle.Regular;

if(Style=="Strikeout") FS=FS^FontStyle.Strikeout;

if(Style=="Underline") FS=FS^FontStyle.Underline;

}

return FS;

}

 

Now you know one. I just made this and it woks great.

When a FontStyle value is saved using Font.Style it looks like this: Bold, Italic, Underline, Strikeout

All you do is send the above method that object and it will return a FontStyle object that you can use in any "new" Font declaration as the style parameter.

 

For example:

 

this.label1.Font=new Font ("Verdana", 10.5, MakeStyle (YourRegistryKeyName.GetValue("FontStyleData")));

Edited by aewarnick
C#
Posted

Here is another one to set the font from the property value: Font

 

the call:

this.label1.Font=MakeFont(YourRegistryKeyName.GetValue("TitleFont"));

 

the method:

public static Font MakeFont(object font)

{

char[]c = {'=', ','};

string sfont = (string)font;

string[]S = sfont.Split(c, 20);

Font NewFont = new Font(S[1], Convert.ToSingle(S[3]));

return NewFont;

}

C#
Posted

Both put together!!!

 

public static Font MakeFont(object font, object fontstyle)

{

char[]c = {'=', ','};

string sfont = (string)font;

string[]S = sfont.Split(c, 20);

 

char[]d={','};

string style=(string)fontstyle; style=style.Replace(" ", "");;

string[]Style=style.Split(d, 6);

FontStyle FS=new FontStyle();

for(int i=0; i<Style.Length; i++)

{

if(Style=="Bold") FS=FS^FontStyle.Bold;

if(Style=="Italic") FS=FS^FontStyle.Italic;

if(Style=="Italic") FS=FS^FontStyle.Italic;

if(Style=="Regular") FS=FS^FontStyle.Regular;

if(Style=="Strikeout") FS=FS^FontStyle.Strikeout;

if(Style=="Underline") FS=FS^FontStyle.Underline;

}

 

Font NewFont = new Font(S[1], Convert.ToSingle(S[3]), FS);

return NewFont;

}

C#
Posted

Use this one instead:

Change: used | instead of ^.

 

public static Font MakeFont(object font, object fontstyle)

{

char[]c = {'=', ','};

string sfont = (string)font;

string[]S = sfont.Split(c, 20);

 

char[]d={','};

string style=(string)fontstyle; style=style.Replace(" ", "");;

string[]Style=style.Split(d, 6);

FontStyle FS=new FontStyle();

for(int i=0; i<Style.Length; i++)

{

if(Style=="Bold") FS=FS | FontStyle.Bold;

if(Style=="Italic") FS=FS | FontStyle.Italic;

if(Style=="Italic") FS=FS | FontStyle.Italic;

if(Style=="Regular") FS=FS | FontStyle.Regular;

if(Style=="Strikeout") FS=FS | FontStyle.Strikeout;

if(Style=="Underline") FS=FS | FontStyle.Underline;

}

 

Font NewFont = new Font(S[1], Convert.ToSingle(S[3]), FS);

return NewFont;

}

C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...