Search code examples
c#.nettextboxgdi+gdi

Does TextBox use GDI or GDI+


Basically, I want to measure the text size in a TextBox, and I found out that TextRenderer gives me the correct values, while Graphics would give me wrong values. So that seems like TextBox should be using GDI to draw text, right?

However, wherever I read, I see that it's supposed to use GDI+. For example:

So why is it that I'm getting consistent results with TextRenderer and not with Graphics when it's supposed to be other way around?


Solution

  • All right, some more research have shown that there is a confusion of what is "Default".

    When these sources talk about "Default", they talk about "Default(1)" as in "If no extra code is executed", not "Default(2)" as in "If no extra action is taken".

    Because by "Default(2)", "Application.SetCompatibleTextRenderingDefault(false)" is added to the Program.cs file of a new proiject, which makes TextBox class use GDI for rendering, which is not the "Default(1)" for it, but in fact this is what happens if you, as a programmer, take no additional action.

    This is basically what got me.

    PS: I'm basing the assumtion that it's true by "Default(1)" on the accepted answer from this question UseCompatibleTextRendering property not created by designer when it is set to false