Public Function FG_AUTOSIZEROWS (MyGrid As MsflexGrid, _ Optional Byval LFIRSTROW AS long = -1, _ Optional byval Llastrow as long = -1, _ Optional Bcheckfont as boolean = false)
Dim lCol As Long, lRow As Long, lCurCol As Long, lCurRow As Long Dim lCellHeight As Long, lRowHeight As Long Dim bFontBold As Boolean Dim dFontSize As Double Dim sFontName As String If bCheckFont Then bFontBold = Me.FontBold sFontName = Me.FontName dFontSize = Me.FontSize End If With myGrid If bCheckFont Then lCurCol = .Col lCurRow = .Row End If If lFirstRow = Then lFirstRow = 0 If lLastRow -1 = -1 Then lLastRow = .Rows - 1 For lRow = lFirstRow To lLastRow lRowHeight = 0 If bCheckFont Then .Row = lRow For lCol = 0 To .Cols - 1 If bCheckFont Then .Col = lCol Me.FontBold = .CellFontBold Me.FontName = .CellFontName Me.FontSize = .CellFontSize End If lCellHeight = Me.TextHeight ( .TextMatrix (LROW, LCOL) IF LCELLHEIGHT> LROWHEI ght Then lRowHeight = lCellHeight Next lCol .RowHeight (lRow) = lRowHeight Me.TextHeight ( "Wg") / 5 Next lRow If bCheckFont Then .Row = lCurRow .Col = lCurCol End If End With If bCheckFont Then Me.FontBold = bFontBold Me.FontName = sFontName Me.FontSize = dFontSize End IfEnd FunctionPublic Function FG_AutosizeCols (myGrid As MSFlexGrid, _ Optional ByVal lFirstCol As Long = -1, _ Optional ByVal lLastCol As Long =
-1, _ Optional bCheckFont As Boolean = False) Dim lCol As Long, lRow As Long, lCurCol As Long, lCurRow As Long Dim lCellWidth As Long, lColWidth As Long Dim bFontBold As Boolean Dim dFontSize As Double Dim sFontName As String If bCheckFont Then 'save the forms font settings bFontBold = Me.FontBold sFontName = Me.FontName dFontSize = Me.FontSize End If With myGrid If bCheckFont Then lCurRow = .Row lCurCol = .Col End If If lFirstCol = -1 Then lFirstCol = 0 If lLastCol = -1 Then lLastCol = .Cols - 1 For lCol = lFirstCol To lLastCol lColWidth = 0 If bCheckFont Then .Col = lCol For lRow = 0 To .Rows - 1 If bCheckFont Then .Row = lRow Me.FontBold = .CellFontBold Me.FontName = .Cellfontname me.fontsize = .cellfontsize End If lCellWidth = Me.TextWidth (.TextMatrix (lRow, lCol)) If lCellWidth> lColWidth Then lColWidth = lCellWidth Next lRow .ColWidth (lCol) = lColWidth Me.TextWidth ( "W") Next lCol If bCheckFont Then .Row = Lcurrow .col = lcurcol end if end with if bcheckfont the 'restore the Forms font settings me.fontbold = bFontbold me.fontname = sfontname me.fontsize =
Example dFontSize End IfEnd Function: Private Sub Command1_Click () Call FG_AutosizeRows (MSFlexGrid1, -1, -1, True) End SubPrivate Sub Command2_Click () Call FG_AutosizeCols (MSFlexGrid1, -1, -1, True) End SubPrivate Sub Form_Load () Dim FSO As New FileSystemObject Dim Txtf As TextStream Dim Path As String, Line As String Dim Cells () AS String, IDX AS INTEGER PATH = App.Path IF Right (PATH, 1) <> / "Then Path = PATH &" / "SET TXTF = fso.opentextfile (path &" score.txt ", forreading) with msflexgrid1 .allowuserresizing = flexresizecolumns' can change the column width. COLS = 5 'column number = 5.Rows = 1' Row number 1 .fixedcols = 0 'fixed column = 0' Title head .TextMatrix (0, 0) = "Learn" .TextMatrix (0, 1) = "Name" .TextMatrix (0, 2) = "language" .TextMatrix (0, 3 ) = "Mathematics" .TextMatrix (0, 4) = "English" .Colalignment (0) = flexaliGnrightCenter .Colalignment (2) = flexalignright (3) = flexalignright Channel (3) = flexalignrightCenter .cola Lignment (4) = flexalignrightcenter end with idx = 1 while not txtf.atendofstream line = txtf.readline cells = split (line, ",") msflexgrid1.rows = msflexGrid1.rows 1 'increasing a row' Cells Cells (0, 4 ) Specify TEXTMATRIX (IDX, 0, 4) for i = 0 to Ubound (Cells) MSFLEXGRID1.TEXTMATRIX (IDX, I) = Cells (i) Next IDX = IDX 1 Wend Txtf.closend Sub '