Help with HtmlListBox.hit_test and painting on DC

I need help getting this code to work.

I am having trouble getting the hit_test to work. It seems to be true
even when the mouse is not over the control (specifically to the right
of the control).

case
when (ht = @htmlctrl.hit_test(@htmlctrl.screen_to_client
evt.get_position)) != NOT_FOUND
# …

I am also trying to paint on a DC. I have attached an example of this.

If you need any additional information please ask.
Thanks in advance.

It seems I forgot to mention that the issue with the DC code is that it
draws under the previous image when the window is resized.

OK. I found a solution for the first issue.
I still need help with painting on a DC.

I fixed it by checking the x position.

case
when (ht = @htmlctrl.hit_test(@htmlctrl.screen_to_client
evt.get_position)) != NOT_FOUND &&
@htmlctrl.screen_to_client(evt.get_position).x <
@htmlctrl.get_client_size.width
# …