Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do multiple font sizes display inside Plain TextBox?

This is not a question about how to change the font size. Rather, why is the size of my font changing by itself as I type (or paste) when it's inside a plain TextBox control which, as you should know, only supports one color, one font, and one font size at any given time.

My code:

using(FontDialog d = new FontDialog())
{
   // The usual properties...
   if(d.ShowDialog() == DialogResult.OK)
   {
      textbox1.Font = d.Font;
   }
}

The font is set at 8pt. If I paste plain text into it, the top line will be 9 to 10pt while the bottom line is noticeably smaller (about 8 pt).

It doesn't matter which font, font style, or font size I choose; this keeps happening!

enter image description here

Update

Thanks for all your help thus far.To answer your recent questions below:

My app is targetting .NET 4.5.

There's no mix up in the code, since I was able to reproduce this problem in a new Windows Forms project with nothing but a Form, a TextBox and a Button that calls the FontDialog.

To answer the question about my Video drivers, I did require support for an app I purchased a few weeks ago and they told me to run DXDiag, they got back to me saying my Video Card driver is out of date, however I didn't think it was because I always check every few months. I then went to the manufacturer's website and it said that I already have the latest drivers installed for my system.

Windows Update also says there are no new available updates. I'll check for a new version of drivers again, though.


I also did a test in a new blank project where I display the font being used by the TextBox before calling FontDialog.ShowDialog(), and after it has been shown and after the new font has been set and everything matches - yet there is still the issues after changing font/font size inside the textbox.

like image 822
jay_t55 Avatar asked May 29 '13 17:05

jay_t55


People also ask

Why are my fonts different sizes?

Both the x-height as well as the cap height of a font affect its legibility, and will make different typefaces look larger or smaller at the same point size. When designers first try out different fonts, they usually look for a size that looks and works best for the demographics and requirements of the design at hand.

Why are font sizes important?

Font size can be used to emphasize particular content Making one piece of text slightly larger than the rest can be a great way to get website users, and potential customers or clients, to really read the content and take notice of your key point or message.


1 Answers

I suspect that the High-DPI screen that you are using is not using an exact multiple of 96 DPI. When in this situation Windows renders your application to a virtual screen that is 96 DPI and then rescales the result to the new DPI. Having a DPI that is not an exact multiple of 96 can cause rounding errors when the application's display is rescaled and as a result fonts can end up looking uneven.

Try setting your DPI to one of the sizes in Appendix C of Microsoft's Writing High-DPI Win32 Applications guide.

like image 82
Martin Brown Avatar answered Oct 23 '22 17:10

Martin Brown