Results 1 to 4 of 4

Thread: [RESOLVED] Msflexgrid metrics

  1. #1

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

    Resolved [RESOLVED] Msflexgrid metrics

    I'm using a msflexgrid to input and edit a square data matrix. It can have 4 different selectable dimensions as in the attached figure: N x N where N is any number from (3, 5, 7, 9). There are no fixed rows or columns.

    Name:  gridz.jpg
Views: 353
Size:  37.7 KB

    I'm confused about how to correctly calculate the overall grid width and height from the individual row height and column width.

    So far I've tried:

    .Width = n * (.ColWidth(0) + (.GridLineWidth + 1) * Tx) + 2 * .BorderStyle * Tx
    .Height = n * (.RowHeight(0) + (.GridLineWidth + 1) * Ty) + 2 * .BorderStyle * Ty

    where n is the number of rows (or columns) and Tx and Ty are variables representing TwipsPerPixelX and TwipsPerPixelY.

    As it is obvious, this is wrong, but I just don't know what I'm missing.
    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
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,745

    Re: Msflexgrid metrics

    According to me, you don't need to take into account the width of the gridlines.
    Code:
    Private Sub Command1_Click()
      With MSFlexGrid1
        .Cols = 5
        .Rows = 4
        .BorderStyle = flexBorderNone
        .ScrollBars = flexScrollBarNone
        .Width = .Cols * .ColWidth(0)
        .Height = .Rows * .RowHeight(0)
        '.ScrollBars = flexScrollBarBoth
        '.Width = .Cols * .ColWidth(0) + Screen.TwipsPerPixelX
        '.Height = .Rows * .RowHeight(0) + Screen.TwipsPerPixelY
      End With
    End Sub
    And if you need a border, then place the MSFlexGrid control inside a picturebox
    Last edited by Arnoutdv; Jun 25th, 2014 at 04:58 AM.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: Msflexgrid metrics

    As each column width may be change (unlike your picture), you might try this as well.

    Code:
    Private Sub Form_Load()
    Dim widthOfAllColumns As Double
    Dim heightOfAllRows As Double
    g1.BorderStyle = flexBorderNone
    g1.ScrollBars = flexScrollBarNone
    Dim x As Integer
    For x = 0 To g1.Cols - 1
        widthOfAllColumns = widthOfAllColumns + g1.ColWidth(x) + g1.GridLineWidth
    Next x
    g1.Width = widthOfAllColumns + g1.GridLineWidth 'take into account the first left vertical line
    For x = 0 To g1.Rows - 1
        heightOfAllRows = heightOfAllRows + g1.RowHeight(x) + g1.GridLineWidth
    Next x
    g1.Height = heightOfAllRows + g1.GridLineWidth
    End Sub

  4. #4

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

    Re: Msflexgrid metrics

    Thanks to Arnoutdv & SamOscarBrown for your 2 different working solutions!

    One thing I completely forgot about was the flexScrollBarNone ScrollBar setting.
    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