Column Width for MSFlexGrid

S

Steven

I develop the application which contains MSFlexGrid to display data. When I
try to fill the grid with the text data, I want to adjust the column width
so that the width is adjusted to the maximum pixel width of the column text
data. I have a function to measure the pixel width of the string data,
however, I found that the parameter of the Set_ColWidth() function in
MSFlexGrid is not in pixel unit. How can I convert the pixel unit to the
unit which is using in MSFlexGrid?
 
H

Herfried K. Wagner [MVP]

Steven said:
I develop the application which contains MSFlexGrid to display data. When I
try to fill the grid with the text data, I want to adjust the column width
so that the width is adjusted to the maximum pixel width of the column text
data. I have a function to measure the pixel width of the string data,
however, I found that the parameter of the Set_ColWidth() function in
MSFlexGrid is not in pixel unit. How can I convert the pixel unit to the
unit which is using in MSFlexGrid?

MSFlexGrid uses twips, but .NET uses pixels. You can use the code below to
convert pixels to twips:

\\\
Private m_TwipsPerPixelX As Integer
Private m_TwipsPerPixelY As Integer
....
Using g As Graphics = Me.CreateGraphics()
m_TwipsPerPixelX = 1440 / g.DpiX
m_TwipsPerPixelY = 1440 / g.DpiY
End Using
....
Me.MSFlexGrid1.ColWidth = 100 * m_TwipsPerPixelX
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top