views:

356

answers:

1

I am trying to figure the best way to programmatically re-size table column headers in ReportViewer.

Basically, my current resolution is the following:

ColumnWidth = HeaderCaption_CharacterCount * 0.32

Where 0.32 is an estimated width of a typical character using my current font size. The issue is that the width leaves a lot of whitespace for longer captions. The more characters a caption has, the more whitespace I end up with.

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

Can someone 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 string of text.

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

I am currently experimenting with this,and it looks promising.

A: 

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

Function calculates the width of a specified string, with a specified font.

Jon