# How to detect MouseOver in general

**URL:** <https://iplug2.discourse.group/t/how-to-detect-mouseover-in-general/177>\
**Category:** Uncategorized\
**Created:** [2 August 2020 22:06 UTC](https://iplug2.discourse.group/t/how-to-detect-mouseover-in-general/177 "2020-08-02T22:06:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cristian\_vogel](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/cristian_vogel/32/68_2.png) [@cristian\_vogel](https://iplug2.discourse.group/u/cristian_vogel)\
**Post date:** [2 August 2020 22:06 UTC](https://iplug2.discourse.group/t/how-to-detect-mouseover-in-general/177/1 "2020-08-02T22:06:02Z")

</div>

Hi.

I am a bit confused about how to attach a MouseOver / MouseLeave event detector to a single control.

Like for example , I might attach three `ITextToggleControls` like this

```
pGraphics->AttachControl(new ITextToggleControl(
                                                           settingWidgetBounds.GetGridCell(0, 0, 1, 3),
                                                           showHideAddresses,
                                                           ICON_FK_CIRCLE_O,
                                                           ICON_FK_QUESTION_CIRCLE_O,
                                                           forkAwesomeText
                                                         )
                                  , kCtrlShowInfo, "prefs");

```

But how would I then attach a MouseOver action/callback to each one? I can’t seem to find a clear example in the Examples folder, and I don’t really understand how the float x and float y in the method signature are supposed to be used

Could someone demonstrate the pattern?

---

<div class="post-metadata">

**Author:** ![AlexHarker](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@AlexHarker](https://iplug2.discourse.group/u/AlexHarker)\
**Post date:** [2 August 2020 22:22 UTC](https://iplug2.discourse.group/t/how-to-detect-mouseover-in-general/177/2 "2020-08-02T22:22:05Z")

</div>

IControl::OnMouseOver is a virtual method you can use to detect mouse overs.

The default is to set a flag and set the control to redraw, and you can then draw differently according to whether there is a mouseover or not. A example of an override can be found on line 423 of IControls.cpp (note the “s” - it’s IControls.cpp not IControl.cpp) - this is for IVTabSwitchControl::OnMouseOver.

Details of what you do in your override will depend on what you wish to achieve.

---

<div class="post-metadata">

**Author:** ![cristian\_vogel](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/cristian_vogel/32/68_2.png) [@cristian\_vogel](https://iplug2.discourse.group/u/cristian_vogel)\
**Post date:** [4 August 2020 21:47 UTC](https://iplug2.discourse.group/t/how-to-detect-mouseover-in-general/177/3 "2020-08-04T21:47:18Z")

</div>

Thanks @AlexHarker - I guess I was stuck because I instantiate and attach a control using the Lambda pattern that is demonstrated throughout the examples ( as in my code clip above ) - the intuitive thing is to then attach a mouseOver call back lambda.

But if I understand it correctly, I need to make a user defined class that is ( in my case ) an ITextToggleControl inherting from the ITextToggleControl base class , which I think is `ITextControl` ?

Then override the mouse virtual function

---

<div class="post-metadata">

**Author:** ![AlexHarker](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@AlexHarker](https://iplug2.discourse.group/u/AlexHarker)\
**Post date:** [4 August 2020 22:06 UTC](https://iplug2.discourse.group/t/how-to-detect-mouseover-in-general/177/4 "2020-08-04T22:06:29Z")

</div>

That sounds about right - I’m not so familiar with all of the built-in controls as I commonly build from scratch, just using Control as a base, so I’m not sure of the details of ITextToggleControl. For much basic stuff you can use the pre-rolled controls, but if you want to get really detailed interactions, at some point you will need to inherit from a suitable base and override methods as needed.

---

<div class="post-metadata">

**Author:** ![cristian\_vogel](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/cristian_vogel/32/68_2.png) [@cristian\_vogel](https://iplug2.discourse.group/u/cristian_vogel)\
**Post date:** [5 August 2020 08:26 UTC](https://iplug2.discourse.group/t/how-to-detect-mouseover-in-general/177/5 "2020-08-05T08:26:31Z")

</div>

got it , brilliant. Thanks!
