registering font style

ayan

Member
Joined
Jun 9, 2004
Messages
18
Programming Experience
Beginner
i don't know how to register the font style. all i have here is the fontname and fontsize. in savesetting...
[vb]
rkfr.SetValue("fontname", RichTextBox1.Font.Name.ToString)
rkfr.SetValue("fontsize", Double.Parse(RichTextBox1.Font.Size))
rkfr.SetValue("fontstyle", RichTextBox1.Font.Style)
[/vb]
and in getsetting...
[vb]
RichTextBox1.Font = New Font(rkfr.GetValue("font").ToString, _
Double.Parse(rkfr.GetValue("fontsize")), rkfr.GetValue("fontstyle"))
[/vb]
it throws an error about overloaded resolution failed. how do i register the fontstyle? sorry for bothers and thanx...
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
The problem is the second parameter, it should be a Single instead of a double.

You can do something like:
VB.NET:
'in savesetting:
rkfr.SetValue("fontsize", RichTextBox1.Font.Size.toString)
'in getsetting:
CSng(rkfr.GetValue("fontsize"))
'or
Ctype(rkfr.GetValue("fontsize"), Single)
 

ayan

Member
Joined
Jun 9, 2004
Messages
18
Programming Experience
Beginner
it accepts my fontsize though. i think it has to do with fontstyle...
VB.NET:
 'set setting
 	  sssk.SetValue("fontname", txt.Font.Name.ToString)
 	  sssk.SetValue("fontsize", Double.Parse(txt.Font.Size))
 	  sssk.SetValue("fontstyle", txt.Font.Style.ToString)
this has the error
VB.NET:
 'get setting
 	  txt.Font = New Font(sssk.GetValue("fontname").ToString, _
 	  Double.Parse(sssk.GetValue("fontsize")))
 'i want to put the third argument as the fontstyle. how do i do that. something
 'like underline and bold or something...
double is ok for fontsize. and oh, thanx for the reply...
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
You can cast the string value of the fontStyle to a fontStyle like this:
VB.NET:
CType(System.Enum.Parse(GetType(FontStyle), "Bold"), FontStyle)
As for the fontSize, the parameter calls for single, so it's best to use a single. But as you said, a double is OK if you like settling for OK :)
 

ayan

Member
Joined
Jun 9, 2004
Messages
18
Programming Experience
Beginner
Paszt said:
VB.NET:
CType(System.Enum.Parse(GetType(FontStyle), "Bold"), FontStyle)
remarkable. thanx very much, paszt...
 
Top Bottom