I currently have a form that has a completely transparent background. At the moment I have to picture boxes that appear at the top of the forum when a user hovers over a control on the form.
Hovering over the PictureBox triggers the MouseEnter
event properly and sets the buttons Visible
state to true and the MouseLeave
event sets it to false. The buttons themselves have the same MouseEnter
and MouseLeave
events but as Winforms passes mouse events to the form under any space on the form that is transparent (my images used in the buttons are transparent around them as well) whenever I go to click the buttons, they disappear as the form thinks that the mouse has "left" both the buttons or the form. Does anyone know ANY way of stopping the pass-through of the events?
Some code you ask? Some code you get :)
// Form Constructor!
// map = picturebox, this = form, move = first button, attach = second button
public Detached(PictureBox map)
{
InitializeComponent();
doEvents(map, this, this.attach, this.move);
}
// doEvents method! I use this to add the event to all controls
// on the form!
void doEvents(params Control[] itm)
{
Control[] ctls = this.Controls.Cast<Control>().Union(itm).ToArray();
foreach (Control ctl in ctls)
{
ctl.MouseEnter += (s, o) =>
{
this.attach.Visible = true;
this.move.Visible = true;
};
ctl.MouseLeave += (s, o) =>
{
this.attach.Visible = false;
this.move.Visible = false;
};
}
}