MSHFlexGrid可以自动设置换行,但换行后行高如何自动调整呢?

lxslhzj 2011-11-09 09:38:54
本人自己也试着解决这个问题,也从网上搜索了一些资料,但没得到有效的解决。
MSHFlexGrid可以自动设置换行,但换行后行高如何才能自动调整呢?不知道高手们有没有遇到个这个问题。
...全文
484 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxslhzj 2011-11-09
  • 打赏
  • 举报
回复
没有AutoSizeMode
  • 打赏
  • 举报
回复
这个例子是当用chr(13)分行有用,用WordWrap,要用其他方法,看上面的注释。
别的没有找到。
神马都能聊 2011-11-09
  • 打赏
  • 举报
回复
楼主你看看那个控件,找找看有没有AutoSizeMode属性或方法。。。
lxslhzj 2011-11-09
  • 打赏
  • 举报
回复
楼上兄弟,这代码不能实现自动换行动自动调整行高功能。
  • 打赏
  • 举报
回复
找到了一个例子。
看看

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
lxslhzj 2011-11-09
  • 打赏
  • 举报
回复
用MSHFlexGrid就没办法实现嘛,主要是其它功能我都开发完了,现在换控件,很麻烦。
  • 打赏
  • 举报
回复
换个空间,vsflexgrid可以
lxslhzj 2011-11-09
  • 打赏
  • 举报
回复
万能的CSDN 真的没有人能解决了嘛。

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧