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
' 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