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?
Printable View
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?
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:
Private Sub Form_Load() Me.ScaleMode = vbPixels MSFlexGrid1.BorderStyle = flexBorderNone End Sub Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Command1.Move MSFlexGrid1.Left + Me.ScaleX(X, vbTwips), _ MSFlexGrid1.Top + Me.ScaleY(Y, vbTwips) End Sub
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:
Private Sub Form_Activate() Dim i As Integer, j As Integer Dim tx As Integer, ty As Integer Dim xoffset As Integer, yoffset As Integer Dim cwpx As Integer, rhpx As Integer Dim cw As Integer, rh As Integer Dim MyBorderThickness As Integer 'Get these valus to be used with the flexgrid 'that uses twips rather than pixels tx = Screen.TwipsPerPixelX ty = Screen.TwipsPerPixelY Me.ScaleMode = vbPixels With grid .Move 0, 0 .GridLineWidth = 1 'Play around with the BorderStyle, 'and number of rows and columns, etc. '----------------------------/------- '.BorderStyle = flexBorderNone .BorderStyle = flexBorderSingle 'This is an educated guess from 'inspecting the grid by eye 'through a desktop magnifier 'utility MyBorderThickness = 2 '----------------------------------- .Cols = 3 .Rows = 4 'I have used very small colwidth and rowheight 'values so as to make pixel counting easier 'ColWidth in pixels: cwpx = 12 'ColWidth in twips cw = cwpx * tx rhpx = 6 'RowHeight in pixels: rh = rhpx * ty For i = 0 To .Cols - 1 .ColWidth(i) = cw Next For i = 0 To .Rows - 1 .RowHeight(i) = rh Next 'Play around with the width and height '(change the offsets) 'to see what are the minimum values 'that don't trigger the scrollbars xoffset = 1 yoffset = -1 .Width = .Cols * cwpx + 2 * MyBorderThickness * .BorderStyle + xoffset .Height = .Rows * rhpx + 2 * MyBorderThickness * .BorderStyle + yoffset ' '---------------------------------------------------- 'Patch around the grid with a chessboard-like pattern 'for easy pixel counting (with a magnifying tool) '---------------------------------------------------- MousePointer = vbHourglass For i = grid.Width - 5 To grid.Width + 5 For j = 0 To grid.Height + 5 If (i + j) Mod 2 = 0 Then Me.PSet (i, j), vbYellow Else Me.PSet (i, j), vbGreen End If Next Next For i = 0 To grid.Width - 6 For j = grid.Height - 5 To grid.Height + 5 If (i + j) Mod 2 = 0 Then Me.PSet (i, j), vbYellow Else Me.PSet (i, j), vbGreen End If Next Next MousePointer = vbDefault End With End Sub
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:
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?VB Code:
With MSFlexGrid1 'Height of horizontal scrollbar VSC_H = GetSystemMetrics(SM_CYHSCROLL) * Screen.TwipsPerPixelX 'Border of horizontal scrollbar VSC_B = GetSystemMetrics(SM_CYBORDER) * Screen.TwipsPerPixelY 'For 25 entirely visible rows: .Height = .RowHeight(0) * 25 + 4 * .BorderStyle * Screen.TwipsPerPixelY+ VSC_H + MyGuess *VSC_B End With
Ok I think it's like this:Quote:
Originally Posted by I myself
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.VB Code:
.Height = .RowHeight(0) * .Rows + 4 * .BorderStyle * Screen.TwipsPerPixelY+ VSC_H + MyGuess * VSC_B