vb macro string width in pixel

前端 未结 9 1512
感动是毒
感动是毒 2020-12-09 06:25

How would you calculate the number of pixels for a String (in an arbitrary font), using an Excel VBA macro?

Related:

  • http://www.mrexcel.com/forum/excel
9条回答
  •  时光取名叫无心
    2020-12-09 06:58

    If you need a mix of fonts sizes etc., why not use:

    DrawText tempDC, Text, Len(Text), wRect, DT_CALCRECT ' Or DT_BOTTOM
    

    instead of

    GetTextExtentPoint32 tempDC, text, Len(text), textSize
    

    with wRect as zero rectangle that returns .cx as .right and .cy as .bottom

提交回复
热议问题