Recent

Author Topic: How to enable OnMouseEnter event when object is not visible  (Read 2684 times)

witenite

  • New Member
  • *
  • Posts: 41
How to enable OnMouseEnter event when object is not visible
« on: August 12, 2018, 09:23:55 am »
Hi,
I've made some really good progress today, but am firmly stuck with this! I have a "Form" that is configured to provide an Alphablend over the main form. It acts as a highlighter for a row of data, and is supposed to move up and down the main form, depending on where the mouse is located. I have all this working, and as I have a row of TEdit boxes down the left hand side, I have a common event that is triggered by these TEdit boxes, whenever the mouse enters or hovers over one of them.

However, I want the horizontal bar to highlight the respective row of data, regardless of where the mouse is located from a latitude perspective. My idea is to use a series of panels (only need 5 of them) that span the width of the of the main form. Then, when entered, they trigger the event mentioned above.

However what I have found is that as soon as the panel/s are hidden (Visible = False) all the events for that panel/s are disabled! Note the "data" I'm talking about is a number of labels etc. that are spread across 3 separate panels, IE not a table. If I had another means of detecting when "Zones" are entered for the main form, that would work too, but for now I'm thinking that a series of hidden panels or similar are the more likely solution.

See the attachment which shows more clearly what I'm trying to achieve, where the  blue overlay/highlight needs to shift to the respective row (1 of 5), depending on mouse position anywhere within a given (row) region.

Any suggestions? I have literally spent hours trying to resolve this.
« Last Edit: August 12, 2018, 01:02:27 pm by witenite »

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: How to enable OnMouseEnter event when object is not visible
« Reply #1 on: August 12, 2018, 09:46:00 am »
I can not quite follow your description but i think you can uses the parent panel's OnMouseEnter. (The parent of the hidden panel)
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to enable OnMouseEnter event when object is not visible
« Reply #2 on: August 12, 2018, 01:23:22 pm »
Controls with Visible = False never receive interaction events: after all, those events can't happen if you're not there, can they?

One relatively common solution is to use OnMouseMove of the parent to calculate which (hidden) control should be under the mouse cursor and make it visible or whatever other action you need to perform.

Another solution is to have a small visible control (e.g. a button) in whose OnMouseEnter handler you can then do whatever you want.

NOTE: It may well be posible that I misunderstood what you wanted. If so, sorry!

Edited to add:
I suppose you thought and discarded it already but, why don't you use some kind of grid control (like TStringsGrid, p.e.)? Seems like it would be the better solution for you.
« Last Edit: August 12, 2018, 01:37:11 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: How to enable OnMouseEnter event when object is not visible
« Reply #3 on: August 12, 2018, 02:24:14 pm »
Controls with Visible = False never receive interaction events: after all, those events can't happen if you're not there, can they?
Indeed. But the observer pattern is implemented for the controls since they inherit from TPersistent, so he could use that.
https://www.freepascal.org/docs-html/rtl/classes/ifpobserved.html and the likes.
« Last Edit: August 12, 2018, 02:26:28 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to enable OnMouseEnter event when object is not visible
« Reply #4 on: August 12, 2018, 02:46:52 pm »
@Thaddy: Hmmm... good point .. or not. I simply don't know enough about that.  ;D Time to (re-)start studying a little bit for me. Thanks! Any possibility of a tiny example?

(I hate not knowing about these things after so many years.  :'( )
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: How to enable OnMouseEnter event when object is not visible
« Reply #5 on: August 12, 2018, 11:20:23 pm »
Looks like something a StringGrid is good for.

The only true wisdom is knowing you know nothing

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: How to enable OnMouseEnter event when object is not visible
« Reply #6 on: August 13, 2018, 03:20:43 am »
Agree a StringGrid would be a solution.

Just knocked up a quick idea use mousemove events etc and painting a tshape, maybe if you don't want to use a stringgrid, this might give a starting point.
It's not the neatest; but it works.

Implemented the mousewheel as well for convenience too

The best way to get accurate information on the forum is to post something wrong and wait for corrections.

 

TinyPortal © 2005-2018