VB.net Property 'Name' is 'ReadOnly'.

Murray Brown
Murray Brown used Ask the Experts™
on
Hi
I have a font name stored as text in a database.
I am trying to use this string to set the font name of a text box in
the line of code below but am getting the error: "Property 'Name' is 'ReadOnly'."

     Dim ChartTitleFontName As String = arrSplit3(1)
     Me.txtChartTitle.Font.Name = ChartTitleFontName
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014
Commented:
You have to create an object of font

Me.txtChartTitle.Font = New Font(ChartTitleFontName, 12)
Top Expert 2015
Commented:
I would go a step further and would not set a hard coded size. This way, if you ever change the FontSize of the TextBox, you code will follow the change:

New Font(ChartTitleFontName, Me.txtChartTitle.Font.Size)

You might want to do that with other characteristics as well (Bold, Italic...)
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thank you both for the help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial