Reputation:
I've been attempting to change the font size of the text within a Data Grid upon choosing a text size from a value fetched from a database. So far I've only managed to change the text within the grid to either be bold or regular and be static size:
GridName.DefaultCellStyle.Font = new Font("Arial",15.00F,FontStyle.Bold);
The code above works, however, I want the "15.00F" to be variable, the value I want to pull it from is stored within a text string, I've tried to convert the font size(string) to a double but it's not letting me use it as the font size. How do I convert a string to a variable that I can replace the fixed font size above (if that makes sense).
GridName.DefaultCellStyle.Font = new Font("Arial",varFontSize,FontStyle.Bold);
Above is essentially what I'm after, I just don't know how to get a valid emSize in the varFontSize variable.
Thank you in advance.
Upvotes: 2
Views: 8877
Reputation: 1549
The Font constructor require a Float value
public Font(
FontFamily family,
float emSize,
FontStyle style
)
In order to parse a string into a float you need to use
float varFontSize= Single.Parse(value);
Then you can
GridName.DefaultCellStyle.Font = new Font("Arial",varFontSize,FontStyle.Bold);
Upvotes: 2
Reputation: 319
I think Blorgbeard answer your question, the value needs to be in float type.
Upvotes: -2