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

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
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CodeCruiserConnect With a Mentor Commented:
You have to create an object of font

Me.txtChartTitle.Font = New Font(ChartTitleFontName, 12)
0
 
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
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...)
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thank you both for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.