Jon
Wed Jun 23 11:58:10 CDT 2004
Herfried K. Wagner [MVP] <hirf-spam-me-here@gmx.at> wrote:
> * Jon Skeet [C# MVP] <skeet@pobox.com> scripsit:
> >> Assigning different font objects has one advantage: Changing the font
> >> of one control doesn't affect other (nested) controls.
> >
> > Are fonts not immutable?
>
> They are immutable.
>
> > There's a big difference between changing
> > which font reference the Font property of the control
> > has and making changes to the font object itself.
>
> It's not possible to make changes to the 'Font' object itself.
>
> > If, as I suspect, font objects are immutable, I don't see the
> > advantage of creating several objects representing the same font.
>
> Well, add a groupbox to your form and add a label to it. Then add code
> to a button that changes the font of the groupbox at runtime. Run the
> application. You will see that the font of the label is changed when
> pressing the button that changes the font of the groupbox. In this
> case, assigning another font object to the label with the same settings
> will prevent the label's font from being changed.
Is there any need to create multiple actual objects though? Won't
Font f = ...;
groupbox.Font = f;
label.Font = f;
do just as well? Note that the OP wasn't complaining about fonts being
explicitly set - he was complaining that multiple font objects were
being created redundantly.
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too