![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi All I am playing around with a form with 280 unbound controls (7 days x 40 time slots per day). I'd like to be able to check the Shift status on each of these controls during the MouseDown event. I can use the MouseDown event procedure: Private Sub Day101_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Shift = 1 Then booShiftDown = True Else booShiftDown = False End If End Sub but I'd have to copy this for each unbound control and modify each one to change the control name and anyway, this seems a very inelegant way to do it!. Anyone know of a way I could assign a function to the MouseDown event on the property sheet ... e.g. =MyShiftCheck() which would assign True or False to the global booShiftDown? Perhaps something to do with screen.activecontrol? It'd be simple to place the function call to all the unbound controls on the MouseDown event. If I'm being very dumb here ... a) not unusual b) please be kind - I need lots of sympathy, I'm a Welsh Rugby supporter! JB |
#3
| |||
| |||
|
|
I am playing around with a form with 280 unbound controls (7 days x 40 time slots per day). I'd like to be able to check the Shift status on each of these controls during the MouseDown event. I can use the MouseDown event procedure: Private Sub Day101_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Shift = 1 Then booShiftDown = True Else booShiftDown = False End If End Sub but I'd have to copy this for each unbound control and modify each one to change the control name and anyway, this seems a very inelegant way to do it!. Anyone know of a way I could assign a function to the MouseDown event on the property sheet ... e.g. =MyShiftCheck() which would assign True or False to the global booShiftDown? Perhaps something to do with screen.activecontrol? It'd be simple to place the function call to all the unbound controls on the MouseDown event. If I'm being very dumb here ... a) not unusual b) please be kind - I need lots of sympathy, I'm a Welsh Rugby supporter! |
#4
| |||
| |||
|
|
jbguernsey wrote: I am playing around with a form with 280 unbound controls (7 days x 40 time slots per day). *I'd like to be able to check the Shift status on each of these controls during the MouseDown event. *I can use the MouseDown event procedure: Private Sub Day101_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Shift = 1 Then * *booShiftDown = True Else * *booShiftDown = False End If End Sub but I'd have to copy this for each unbound control and modify each one to change the control name and anyway, this seems a very inelegant way to do it!. Anyone know of a way I could assign a function to the MouseDown event on the property sheet ... e.g. =MyShiftCheck() which would assign True or False to the global booShiftDown? *Perhaps something to do with screen.activecontrol? It'd be simple to place the function call to all the unbound controls on the MouseDown event. If I'm being very dumb here ... a) not unusual b) please be kind - I need lots of sympathy, I'm a Welsh Rugby supporter! Not dumb at all, and neither are rugby players *;-) The problem is that the MouseDown event knows how to call the event procedure with all those arguments. *That capabilit is lost when you put a function call in an event property. If all of your unbound controls are arranged in a tight rectanglar grid pattern, then the way I deal with it is to place a transparent command button exactly over the grid of controls. *This way the transparent command button's MouseDown event is called and the problem becomes how to figure which unbound control the mouse is over. Name the unbound controls with a numeric suffix that tells you its row and column in the grid. *E.g: * *Day0000 * Day0001 * Day0002 * Day0003 * *Day0100 * Day0101 * Day0102 * Day0103 * *Day0200 * Day0201 * Day0202 * Day0203 Then, assuming the grid of unbound controls under the big button have no gaps between them and they are all the same size, you can calculate the name of the control that has the mouse over it: Private Sub BigButton_MouseDown(Button As Integer, _ * * * * * * * * Shift As Integer, X As *Single, Y As Single) Dim Row As Integer, Col As Integer Dim ControlName As String * *Row = Y \ Me.Day0000.Height * *Col = X \ Me.Day0000.Width * *ControlName = "Day" & Format(Row, "00") & *Format(Col, "00") * * * * 'set the value of the unbound control??? * *Me(ControlName) = 1 * * * * ' set the ShiftDown variable (Why is this useful?) * *If Shift = 1 Then * * * booShiftDown = True * *Else * * * booShiftDown = False * *End If *End Sub You probably want to do something else with the clicked unbound control, but I think that above demonstrates all you need to do whatever you want. -- Marsh |
#5
| |||
| |||
|
|
The reason for the Shift stuff is that I'd like an 'easy' way for the user to select a (vertical) block of 'cells' and I thought a Shift- Click following the original click in a 'cell' would be nice and easy (for the user). *I have found that the MouseOver event stuff is just not reliable enough to use - it doesn't seem to be able to keep up with swift mouse movements: therefore I don't use click and drag. Anyway, thanks again for the idea, *I'll give it some thought and see what transpires. JB- Hide quoted text - - Show quoted text - |
#6
| |||
| |||
|
|
The reason for the Shift stuff is that I'd like an 'easy' way for the user to select a (vertical) block of 'cells' and I thought a Shift- Click following the original click in a 'cell' would be nice and easy (for the user). *I have found that the MouseOver event stuff is just not reliable enough to use - it doesn't seem to be able to keep up with swift mouse movements: therefore I don't use click and drag. Anyway, thanks again for the idea, *I'll give it some thought and see what transpires. JB- Hide quoted text - - Show quoted text - Hi JB, Because I use very generalized forms, I use these kind of techniques quite intensively. Let us assume you use the OnClick event to define the selected controls. Anyway, you have to catch the OnClick events of each of the 280 controls you have. This is easily done by declaring: Private Sub Day101_Click() * * On_Click Me, 101 * * *or *On_Click Me, “Day101” End Sub Etc. If 280 times is too much work, you can make a small VBA-routines, that generates an a txt-file with all the necessary declarations that can be included in the form module with copy/paste. The On_Click procedure contains all the knowledge on how you want to work with your controls. Using Me as a parameter has the advantage that you can place this Sub in any module without loosing the information of the used form, and you can generalize it for other forms. On the form you can define a unvisible Last_clicked control, whereas the new_clicked control is passed as second parameter to the On_Click sub. In principle you now have enough information to do what you want. Imb. |
![]() |
| Thread Tools | |
| Display Modes | |
| |