Column Width for MSFlexGrid

  • Thread starter Thread starter Steven
  • Start date Start date
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?
 
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
///
 
Back
Top