Copying Font Properties


Say you have a user control that contains some other web controls, such as a text box or drop down list.  Now say that you want the UI designer to be able to set the font properties of the contained controls, by setting the font properties of the control in the designer.  Well, if you’ve ever tried this:


this.myContainedControl.Font = this.Font;


You’ll find that the Font property is read only.  You can set the individual properties, but this would be a pain for all of the properties that the FontInfo object supports.  Luckily, the FontInfo object has a CopyFrom method, which you can use to do accomplish this task in one fell swoop:


this.myContainedControl.Font.CopyFrom(this.Font);


Music tip o’ the day: If you like REM, check out Placebo

About Brendan Tompkins

Brendan runs CodeBetter.Com and Devlicio.Us. He is a former MVP for Microsoft .NET and is president of Port Technology Services, a partner with Port Solution Integrators a provider of hardware and software integration services for the transportation and logistics industry.
This entry was posted in .NET General. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://xehwuwer.com/ Bwqjzkgj

    IGQvCl

  • Steve

    Nice! Why couldn’t you have posted this a couple of months ago when I was trying to figure out why they would make it such a pain to copy font’s between controls? :) Thanks for the tip!