在VB6的VSFlexGrid控件中,复选框默认是左对齐的,并且无法直接通过控件属性来居中复选框。可以使用一些技巧来实现复选框的居中显示。
一种方法是使用自定义绘制(Custom Draw)来绘制一个居中的复选框。以下是一个示例代码,演示如何使用自定义绘制将复选框居中显示:
vb
Private Sub VSFlexGrid1_OLEDragCellMouseMove(ByVal ColIndex As Integer, ByVal RowIndex As Integer, _
ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single, ByVal DragState As Integer)
If ColIndex = 16 Then
VSFlexGrid1.CustomDraw = flexcdTextBk + flexcdForeColor
VSFlexGrid1.CellPictureAlignment = flexAlignCenterCenter
Else
VSFlexGrid1.CustomDraw = flexcdNone
End If
End Sub
Private Sub VSFlexGrid1_OLEDragOver(ByVal Data As MSComctlLib.DataObject, _
ByVal Effect As MSComctlLib.OLEDropEffect, ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single, ByVal State As Integer)
Dim sState As String
' 设置复选框状态
If Effect = flexDROPEFFECT_CHECKBOX Then
If VSFlexGrid1.TextMatrix(VSFlexGrid1.MouseRow, 16) = "" Then
sState = "0"
Else
sState = VSFlexGrid1.TextMatrix(VSFlexGrid1.MouseRow, 16)
End If
VSFlexGrid1.TextMatrix(VSFlexGrid1.MouseRow, 16) = IIf(sState = "0", "1", "0")
End If
End Sub
[此贴子已经被作者于2023-10-25 21:39编辑过]