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

MSFlexGrid控件有关问题

2012-01-11 
MSFlexGrid控件问题请问怎么设置MSFlexGrid的一列为ComboBox,一列为CheckBox,一列为Button?[解决办法]Opti

MSFlexGrid控件问题
请问怎么设置MSFlexGrid的一列为ComboBox,一列为CheckBox,一列为Button?

[解决办法]
Option Explicit

Private Sub fg_BeforeMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single, Cancel As Boolean)

' only interesetd in left button
If Button <> 1 Then Exit Sub

' get cell that was clicked
Dim r&, c&
r = fg.MouseRow
c = fg.MouseCol

' make sure the click was on the sheet
If r < 0 Or c < 0 Then Exit Sub

' make sure the click was on a cell with a button
If Not (fg.Cell(flexcpPicture, r, c) Is imgBtnUp) Then Exit Sub

' make sure the click was on the button (not just on the cell)
' note: this works for right-aligned buttons
Dim d!
d = fg.Cell(flexcpLeft, r, c) + fg.Cell(flexcpWidth, r, c) - X
If d > imgBtnDn.Width Then Exit Sub

' click was on a button: do the work
fg.Cell(flexcpPicture, r, c) = imgBtnDn
MsgBox "Thanks for clicking my custom button! "
fg.Cell(flexcpPicture, r, c) = imgBtnUp

' cancel default processing
' note: this is not strictly necessary in this case, because
' the dialog box already stole the focus etc, but let 's be safe.
Cancel = True

End Sub

Private Sub Form_Load()

' initialize grid
fg.Editable = flexEDKbdMouse
fg.AllowUserResizing = flexResizeBoth

' add some buttons to the grid
Dim i%
For i = 2 To 6
fg.Cell(flexcpPicture, i, 2) = imgBtnUp
fg.Cell(flexcpPictureAlignment, i, 2) = flexAlignRightCenter
Next

End Sub

Private Sub Form_Resize()
On Error Resume Next
fg.Move fg.Left, fg.Top, ScaleWidth - 2 * fg.Left, ScaleHeight - fg.Left - fg.Top
End Sub

热点排行