-
Nov 29th, 2021, 09:56 PM
#1
Thread Starter
New Member
MouseOver Event doesn't work when object hidden
VS 2008 "VB" simple control panel simulation (circa XP era) converted to run in W10 using VS 2019
Main Form has a graphic with 16 "Numbered" Indicators 1-16 showing all 16 indicators in their ON state (colored RED)
Each indicator has an overlay Picturebox to indicate an OFF state (colored GREY) ... basically simulating 16 Red LEDs ... when the Picturebox is shown the indicator is in its OFF state ... when the Picturebox is hidden the indicator is in its ON state
A recent change was made to this application to allow a description to pop up over each Indicator using MouseOver Events linked to these PictureBox objects
The Key failure with this simple implementation is that the designated MouseOver Event won't trigger when the Picturebox object is hidden meaning the description will only show up when the indicator is in its OFF State
These descriptions need to be available when mousing over an indicator regardless of its state
The solution that comes to mind would be to add 16 individual ON State Pictureboxes under the OFF state Pictureboxes (each with its own mouseover event) The underlying Red Graphics would never be seen again ... not sure if both objects could be on at the same time (using the existing ON/OFF State logic) OR if more logic is required to Hide/Show the opposite state objects
Is there some other Form OBJECT that can be used to define the bounds of these indicators that could be used to trigger a mouseover event regardless of the STATE of the Indicator's PictureBox?
Or is there another way to implement a 2 state indicator object that could always have a mouseover description?
Thanks in advance for your time
-
Nov 30th, 2021, 12:36 AM
#2
Re: MouseOver Event doesn't work when object hidden
Instead of using pictureboxes, use a panel with graphics. GDI+ makes it easy to draw rectangles, filled rectangles, etc. use the panel’ mouse move, mousedown etc. Just takes some simple arithmetic…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 30th, 2021, 02:59 AM
#3
Re: MouseOver Event doesn't work when object hidden
You can see an example of what .paul. is talking about here. There are plenty of other examples around but just be aware that many of them lazily call CreateGraphics, which is something you should never do.
Note that I would generally suggest that you do use a PictureBox still, but only one. It is optimised for GDI+ so will perform better than a Panel.
-
Nov 30th, 2021, 08:18 AM
#4
Re: MouseOver Event doesn't work when object hidden
Here's another way to do it that would require fewer changes.
Instead of hiding the 'overlay' picturebox, set its background to near total transparency, e.g. alpha=1. As long as the alpha is more than zero, the overlay will continue to raise mouse events.
However, the transparency only works if the visible LED you want to hide is the parent of the overlay. So assuming the LED is itself a control such as a picturebox:
Code:
'set parent e.g. in Load event:
pbOverlay.Parent = pbLED
pbOverlay.Location = Point.Empty
'hide the LED (alpha=255):
pbOverlay.BackColor = Me.BackColor
'show the LED (alpha=1):
pbOverlay.BackColor = Color.FromARGB(1, Me.BackColor)
BB
Last edited by boops boops; Nov 30th, 2021 at 08:25 AM.
-
Nov 30th, 2021, 07:38 PM
#5
Thread Starter
New Member
Re: MouseOver Event doesn't work when object hidden
Instead of hiding the 'overlay' picturebox, set its background to near total transparency,
I was actually trying something like that today
Each Picturebox has a bmp file associated with it so I took one and converted it to a gif (gif has the ability to have an assigned transparent color) ... the reason for the bit map image is it contains the numeric value of the indicator with the appropriate background-color
The expectation was that using the Picturebox background color method would show the background color through the transparent color defined by the gif
ON Code
Code:
Me.Z1.BackColor.FromArgb(224,64,128)
OFF Code
Code:
Me.Z1.BackColor.FromArgb(128,128,128)
The expected result for ON Code was supposed to be Red
The expected result for OFF Code was supposed to be Grey
The actual result FOR BOTH was a Navy Blue (approximately 90,108,160 screen capture dithered the colors)
Also before adding the background color code the loaded gif didn't show the underlying color of the main bmp suggesting that the Picturebox may be ignoring the Transparency Flag of the GIF ... or ... could be that the picturebox has a default background color which is more likely
The Resource manager shows the gif with the expected transparent background so expecting there may be some conflict with the picture box color and the gif transparency color (set to 128,128,128) ... perhaps I should try setting a color of 0,0,0 for the Transparency Color of the GIF
Was also looking at the possibility of swapping the bmp resource off the picture box ... both methods would not require hiding the picturebox for an on state ... the swap method would most likely be more resource-intense
Last edited by bxdobs; Nov 30th, 2021 at 07:47 PM.
-
Nov 30th, 2021, 07:48 PM
#6
Re: MouseOver Event doesn't work when object hidden
The color object takes an overload of Alpha, Red, Green, Blue. The overload you’re using is just Red, Green, Blue
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|