Auto resizing columns based on char count

I am trying to figure out the best way to programmatically repartition the table column headers in the ReportViewer.

Basically, my current resolution is as follows:

ColumnWidth = HeaderCaption_CharacterCount * 0.32

      

Where 0.32 is the estimated width of a typical character using my current font size. The problem is that the width leaves a lot of gaps for longer titles. The more characters have a signature, the more spaces I get.

The problem with evaluating this way is that not all characters are the same width. A good example would be the "I" character, which takes up less screen width than the rest of the alphabet.

Can anyone suggest a better way to do this?

EDIT I found a better way to handle this. There is a method that will calculate the width (in pixels) of a line of text.

Size = TextRenderer.MeasureText([String], [Font])

      

I am currently experimenting with this and it looks promising.

0


a source to share


1 answer


Size = TextRenderer.MeasureText([String], [Font])



The function calculates the width of the specified string with the specified font.

0


a source







All Articles