Any way to generically detect a click anywhere?

BurninSun

New Member
Licensed User
I'm currently working on a form that will have a scrolling list of records but each record can have different types of information. I plan on creating panels on the fly, one panel per record; filling them with labels, which may even be multiline; then using the ControlsEx scrollbar to adjust the .top of each panel (as well as .height and .show/.hide) to simulate a scrolling list.

The problem I'm having is that I need to be able to click anywhere on these panels to select one record which will then go to another form for editing that record. My initial ideas were to create a button over each panel set to transparent so that the underlying labels would show, or to make the labels disabled and use the click event of the underlying panel to detect a click. Neither of these seem work. Lastly, I thought of trying to detect a generic click and comparing the x/y positions with the bounds of all the displayed panels but I can't find a way to do this either.

Failing these options, I could change every label into a button and hook the click event of every button and the underlying panel into the same function but this seems a bit of overkill for what I'm trying to do. Anyone have any other ideas?

This is for use on a PPC running WM6.

Thanks in advance.
 

BurninSun

New Member
Licensed User
I believe you can detect the x/y coordinates by using the door library (see e.g. this thread: http://www.b4x.com/forum/questions-help-needed/2517-get-x-y-when-over-control.html)

I was hoping to avoid attaching an event to every object on my form, but if all else fails, this is what I'll have to go with.

An alternative which I have used is to actually only employ a small number of labels with fixed positions, and just change the content of the labels instead of actually creating a large number of labels/panels.

This is a good idea and I might use it in another part of my program but it won't work in this case. Here, some of my records contain only 1 label while others can have as many as 20 on multiple lines.
 

BurninSun

New Member
Licensed User
I had set this problem aside while I worked on some other things, but now that I've come back to it, I found a solution. So for anyone who needs something similar, here it is.

Using dzEventsMagic, I hooked event #512 (WM_MOUSEFIRST) then simply read off the lParam when the event is fired. lParam is a 4 byte value where the low 2 bytes are the X coord and the high 2 bytes are the Y coord. This will detect a "click through" of an enabled label on the form/panel that is hooked. (Note that the desktop version will detect a click through only if the label is DISABLED, while the device version will detect on ENABLED labels only)

B4X:
' Create a form "form1" including a panel "panel1" and a label "label1"
' label1 should be parented to panel1 and placed inside panel1
Sub App_Start
   ' dzem is a dzEventsMagic object
   dzem.New1("Panel1", true)
   dzem.Hook(512) 'WM_MOUSEFIRST
   Form1.Show
End Sub

Sub dzem_MagicEvent
   'yes i know this is ugly, should use bitwise functions
   label1.Text = Int(dzem.lParam/65536,0) & " x " & dzem.lParam-Int(dzem.lParam/65536,0)*65536
End Sub

Sub Form1_Show

End Sub

Sub Form1_Close
   dzem.Unhook(512)
End Sub


Clicking on the panel (or the label) will show the clicked coordinates within the panel. (Again, note that if on the desktop, the label must be DISABLED for this to work properly. On the device, the label must be ENABLED)

So back to my original problem. I can simply make a panel for each "row" of data, fill it with appropriate labels, and hook the entire panel to detect clicks on that panel. Then move/hide the panels as necessary based on the scrollbar and I now have a custom made scroll box.
 
Top