Properties of Font-class are all read-only ???

  • Thread starter Thread starter Christian Cambier
  • Start date Start date
C

Christian Cambier

Hi,

the following produces a compiler error :

label1.Font.Size = 10;

==> ERROR:Property or indexer 'System.Drawing.Font.Size' cannot be
assigned to -- it is read only

OK, but why has it been designed as read-only. As are all properties of the
Font-class by the way (???)

Is there no way I can set the individual properties of a Font-object ?

thnx

Chris
 
Christian

I think the font object's properties are read only because of the underlying implementation in windows. (See CreateFont API for more info). If you want to change the size, create a new instance of font passing the same family etc... but a different size

Hope that help
Jackson Davis [MSFT
-
This posting is provided "AS IS" with no warranties, and confers no rights
OR if you wish to include a script sample in your post please add "Use o
included script samples are subject to the terms specified a
http://www.microsoft.com/info/cpyright.htm
 
No, once you create a font, you can't change it. There are a number of
reasons for this, but it's all basically because that's the way fonts are
handled in Windows. A 12 point font and a 10 point font that are otherwise
identical are considered two entirely separate fonts.

Underneath, each has a separate font handle and thus the encapsulation in
..NET works the same way.

Pete
 
Back
Top