注册 登录
编程论坛 VB6论坛

vb6的VSFlexGrid控件中的Checked复选框为什么不居中?

牛掰 发布于 2023-05-11 10:04, 2034 次点击
vb6的VSFlexGrid控件中的Checked复选框为什么不居中?或者有什么办法让复选框居中吗?
现代码如下:
With VSFlexGrid1
    .Cell(flexcpChecked, 1, 6, .Rows - 1, 16) = 2
end with
只有本站会员才能查看附件,请 登录


[此贴子已经被作者于2023-5-11 10:07编辑过]

4 回复
#2
kings123332023-05-20 13:51
回复 楼主 牛掰
兄弟,你这个Grid的隔行显示的真漂亮,分享一个例子..
#3
wlbwxd2023-10-25 21:29
在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编辑过]

#4
牛掰2023-10-31 16:08
回复 3楼 wlbwxd
只有本站会员才能查看附件,请 登录
,谢谢老师的代码,但是运行后报错了,提示如图片上面所示!
#5
牛掰2023-11-02 13:01
顶一下
1