Results 1 to 5 of 5

Thread: MSFlexGrids and scale

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    MSFlexGrids and scale

    I've noticed that flexgrids don't have a scalemode property so values as colwidth must be assigned in twips. Is that so or am I missing something?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: MSFlexGrids and scale

    that's correct - if you're worried about it matching up with the form's scalemode then you can use the ScaleX and ScaleY functions, e.g.:
    VB Code:
    1. Private Sub Form_Load()
    2.     Me.ScaleMode = vbPixels
    3.     MSFlexGrid1.BorderStyle = flexBorderNone
    4. End Sub
    5.  
    6. Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    7.     Command1.Move MSFlexGrid1.Left + Me.ScaleX(X, vbTwips), _
    8.                   MSFlexGrid1.Top + Me.ScaleY(Y, vbTwips)
    9. End Sub

  3. #3

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: MSFlexGrids and scale

    What I'm actually worried about is the grid metrics. I've recently posted some query about the correct gid size so that an integer number of cols & rows fitted in it. I wanted to know what the border width was in various practical cases and things like these.

    As no one has provided a definite formula I have made a study project to try to learn by eye inspection. I have used a grid with very small cells and a desktop magnifier tool. I have attached the project as well as a spyglass (in case you don't have one handy) that I downloaded God knows where.

    I have found that the grid thickness seems to be 2*BorderStyle, so it's either 0 or 2, but in one case I found a border thichness of 3 pixels -but I just can't remember what property I changed.

    On the other hand, there are two variables, xoffset and yoffset to help find what were the minum grid width and height that would clip the rightmost column or and downmost row that make the scrollbars appear.

    Well, do me a favor, play around with this thing and let me know what you think.
    VB Code:
    1. Private Sub Form_Activate()
    2.     Dim i As Integer, j As Integer
    3.     Dim tx As Integer, ty As Integer
    4.     Dim xoffset As Integer, yoffset As Integer
    5.     Dim cwpx As Integer, rhpx As Integer
    6.     Dim cw As Integer, rh As Integer
    7.     Dim MyBorderThickness As Integer
    8.    
    9.     'Get these valus to be used with the flexgrid
    10.     'that uses twips rather than pixels
    11.     tx = Screen.TwipsPerPixelX
    12.     ty = Screen.TwipsPerPixelY
    13.    
    14.     Me.ScaleMode = vbPixels
    15.    
    16.     With grid
    17.         .Move 0, 0
    18.         .GridLineWidth = 1
    19.         'Play around with the BorderStyle,
    20.         'and number of rows and columns, etc.
    21.         '----------------------------/-------
    22.         '.BorderStyle = flexBorderNone
    23.         .BorderStyle = flexBorderSingle
    24.         'This is an educated guess from
    25.         'inspecting the grid by eye
    26.         'through a desktop magnifier
    27.         'utility
    28.         MyBorderThickness = 2
    29.         '-----------------------------------
    30.         .Cols = 3
    31.         .Rows = 4
    32.         'I have used very small colwidth and rowheight
    33.         'values so as to make pixel counting easier
    34.         'ColWidth in pixels:
    35.         cwpx = 12
    36.         'ColWidth in twips
    37.         cw = cwpx * tx
    38.         rhpx = 6
    39.         'RowHeight in pixels:
    40.         rh = rhpx * ty
    41.         For i = 0 To .Cols - 1
    42.             .ColWidth(i) = cw
    43.         Next
    44.         For i = 0 To .Rows - 1
    45.             .RowHeight(i) = rh
    46.         Next
    47.         'Play around with the width and height
    48.         '(change the offsets)
    49.         'to see what are the minimum values
    50.         'that don't trigger the scrollbars
    51.         xoffset = 1
    52.         yoffset = -1
    53.         .Width = .Cols * cwpx + 2 * MyBorderThickness * .BorderStyle + xoffset
    54.         .Height = .Rows * rhpx + 2 * MyBorderThickness * .BorderStyle + yoffset
    55.         '
    56.         '----------------------------------------------------
    57.         'Patch around the grid with a chessboard-like pattern
    58.         'for easy pixel counting (with a magnifying tool)
    59.         '----------------------------------------------------
    60.         MousePointer = vbHourglass
    61.        
    62.         For i = grid.Width - 5 To grid.Width + 5
    63.             For j = 0 To grid.Height + 5
    64.                 If (i + j) Mod 2 = 0 Then
    65.                     Me.PSet (i, j), vbYellow
    66.                 Else
    67.                     Me.PSet (i, j), vbGreen
    68.                 End If
    69.             Next
    70.         Next
    71.         For i = 0 To grid.Width - 6
    72.             For j = grid.Height - 5 To grid.Height + 5
    73.                 If (i + j) Mod 2 = 0 Then
    74.                     Me.PSet (i, j), vbYellow
    75.                 Else
    76.                     Me.PSet (i, j), vbGreen
    77.                 End If
    78.             Next
    79.         Next
    80.        
    81.         MousePointer = vbDefault
    82.        
    83.     End With
    84.    
    85. End Sub
    Attached Files Attached Files
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: MSFlexGrids and scale

    Another issue is, if there's a horizontal scrollbar, what should the grid height be so that an integer number of rows are completely visible (i.e. not clipped)?

    I thought I could derive this by trial and error but the figures I'm getting make no sense. For example, my last attempt was:
    VB Code:
    1. With MSFlexGrid1
    2.     'Height of horizontal scrollbar
    3.     VSC_H = GetSystemMetrics(SM_CYHSCROLL) * Screen.TwipsPerPixelX
    4.     'Border of horizontal scrollbar
    5.     VSC_B = GetSystemMetrics(SM_CYBORDER) * Screen.TwipsPerPixelY
    6.     'For 25 entirely visible rows:
    7.     .Height = .RowHeight(0) * 25 + 4 * .BorderStyle * Screen.TwipsPerPixelY+ VSC_H + MyGuess *VSC_B
    8. End With
    As the returned VSC_B value was 1 pixel, I tried different values of MyGuess and it turned out that 17 was the minimum value that didn't call for a vertical scrollbar, meaning that the rows were visible. So why 17?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  5. #5

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: MSFlexGrids and scale

    Quote Originally Posted by I myself
    Another issue is, if there's a horizontal scrollbar, what should the grid height be so that an integer number of rows are completely visible (i.e. not clipped)?

    I thought I could derive this by trial and error but the figures I'm getting make no sense. For example, my last attempt was:
    VB Code:
    1. With MSFlexGrid1
    2.     'Height of horizontal scrollbar
    3.     VSC_H = GetSystemMetrics(SM_CYHSCROLL) * Screen.TwipsPerPixelX
    4.     'Border of horizontal scrollbar
    5.     VSC_B = GetSystemMetrics(SM_CYBORDER) * Screen.TwipsPerPixelY
    6.     'For 25 entirely visible rows:
    7.     .Height = .RowHeight(0) * 25 + 4 * .BorderStyle * Screen.TwipsPerPixelY+ VSC_H + MyGuess *VSC_B
    8. End With
    As the returned VSC_B value was 1 pixel, I tried different values of MyGuess and it turned out that 17 was the minimum value that didn't call for a vertical scrollbar, meaning that the rows were visible. So why 17?
    Ok I think it's like this:
    VB Code:
    1. .Height = .RowHeight(0) * .Rows + 4 * .BorderStyle * Screen.TwipsPerPixelY+ VSC_H + MyGuess * VSC_B
    Now, if MyGuess is 1 this is the minimum value necessary to avoid a vertical scrollbar, but you need MyGuess=2 to make the last row completely visible.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width