首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

MSHFlexGrid可以自动设置换行,但换行后行高怎么自动调整呢

2012-04-09 
MSHFlexGrid可以自动设置换行,但换行后行高如何自动调整呢?本人自己也试着解决这个问题,也从网上搜索了一

MSHFlexGrid可以自动设置换行,但换行后行高如何自动调整呢?
本人自己也试着解决这个问题,也从网上搜索了一些资料,但没得到有效的解决。
MSHFlexGrid可以自动设置换行,但换行后行高如何才能自动调整呢?不知道高手们有没有遇到个这个问题。

[解决办法]
换个空间,vsflexgrid可以
[解决办法]
找到了一个例子。
看看

Public Function FG_AutosizeRows(myGrid As MSFlexGrid, _
Optional ByVal lFirstRow As Long = -1, _
Optional ByVal lLastRow As Long = -1, _
Optional bCheckFont As Boolean = False)

' This will only work for Cells with a Chr(13) 
' To have it working with WordWrap enabled
' you need some other routine
' Which has been added too
 
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
' save the forms font settings
bFontBold = Me.FontBold
sFontName = Me.FontName
dFontSize = Me.FontSize
End If
  
With myGrid
If bCheckFont Then
lCurCol = .Col
lCurRow = .Row
End If

If lFirstRow = -1 Then lFirstRow = 0
If lLastRow = -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 > lRowHeight 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
' restore the forms font settings
Me.FontBold = bFontBold
Me.FontName = sFontName
Me.FontSize = dFontSize
End If
  
End Function

Public 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 Then
' restore the forms font settings
Me.FontBold = bFontBold
Me.FontName = sFontName
Me.FontSize = dFontSize
End If
  
End Function
[解决办法]
楼主你看看那个控件,找找看有没有AutoSizeMode属性或方法。。。

热点排行