Flexgrid - Clicking Resize handles

bobm5
02-09-2005, 09:40 PM
Hi,

I'm using a flexgrid in my VB6 app. I just want to know if it is possible to detect a click for when you click on the resize handles in the fixed columns & rows.

I want to do something similar to excel where when you double click on the resizer and it autosizes the column/row. I've searched all over and can't find anything about this.

Here's what i've tried so far. I hope there's a nice simple way to do this :)

Private Sub Grid_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)

Col0_1 = Grid.ColPos(0) + Grid.ColWidth(0) ' Between Col 0 & Col 1
If x = Col0_1 Then
MsgBox "Clicked Between Column 0 and 1"
End If
End Sub

The mouseup event fires when the handles are double-clicked but the value of x doesn't seem to be very reliable.

In this calse Col0_1 was 690. When Double-clicking on the handles x becomes 675.

I also used the mousemove event to output the value of x in the status bar.
when i moved over the resize handles it showed 690, but after double-clicking x was still 675 in the mouseup event. Could this be some timing issue?


Thanks
Bob

Flyguy
02-10-2005, 02:22 AM
Try this:

Option Explicit

Private m_X As Single
Private m_lCol As Long
Private m_bResize As Boolean

Private Sub MSFlexGrid1_DblClick()
Dim bAutoSize As Boolean

If m_bResize Then
With MSFlexGrid1
If m_X >= .ColPos(m_lCol) + .ColWidth(m_lCol) - 2 * Screen.TwipsPerPixelX Then bAutoSize = True
If m_X <= .ColPos(m_lCol) + Screen.TwipsPerPixelX Then bAutoSize = True
End With
m_bResize = False
If bAutoSize Then MsgBox "Autosize"
End If
End Sub

Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)

With MSFlexGrid1
m_lCol = .MouseCol
If .MouseRow < .FixedRows Then
m_X = x
m_bResize = True
End If
End With

End Sub


For some additional autosize code have a look in the .. thread

bobm5
02-10-2005, 04:52 PM
Thanks FlyGuy! :)

That code worked great. I had to modify it slightly because I found that the DblClick event triggers before the MouseUp event.

Thanks Again :)

For those that are interested, here's my final code:


Private DidDblClick As Boolean

Private Sub Grid_DblClick()
With Grid
' Check if the cell clicked is a fixed cell. If it is then do nothing.
If .MouseRow < .FixedRows Or .MouseCol < .FixedCols Then
DidDblClick = True
End If
End With
End Sub


Private Sub Grid_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

' Do the AutoSize Column/Row
If DidDblClick Then
DidDblClick = False

Dim SizeCol As Boolean, SizeRow As Boolean
SizeCol = False
SizeRow = False

With Grid
TheCol = .MouseCol
TheRow = .MouseRow

If X >= .ColPos(TheCol) + .ColWidth(TheCol) - 2 * Screen.TwipsPerPixelX Then
SizeCol = True
End If
If X <= .ColPos(TheCol) + Screen.TwipsPerPixelX Then
SizeCol = True
End If


If Y >= .RowPos(TheRow) + .RowHeight(TheRow) - 2 * Screen.TwipsPerPixelY Then
SizeRow = True
End If
If Y <= .RowPos(TheRow) + Screen.TwipsPerPixelY Then
SizeRow = True
End If

If SizeCol Then
MsgBox "AutoSize Col " & TheCol
End If

If SizeRow Then
MsgBox "AutoSize Row " & TheRow
End If
End With
End If

End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum