Measure a String without using a Graphics object?

前端 未结 5 1079
梦谈多话
梦谈多话 2020-11-27 19:57

I am using pixels as the unit for my font. In one place, I am performing a hit test to check if the user has clicked within the bounding rectangle of some text on screen. I

5条回答
  •  暖寄归人
    2020-11-27 20:29

    If you have a reference to System.Windows.Forms, try using the TextRenderer class. There is a static method (MeasureText) which takes the string and font and returns the size. MSDN Link

提交回复
热议问题