Scene: A (small) form on which the UserControl is placed.
Plot: whenever UserControl raises a hover event, display some (graphical) information in the form of a hint. When the user moves the mouse, extinguish them again.
Notes. I would like to display more than one "hint", and each hint is a UserControl that displays information graphically. Not just text in the yellow box! In addition, I use the Windows.Forms library.
This is what I have so far:
private void myControl_Hovered(object sender, MyEventArgs e)
{
var tooltip = new MyToolTip();
Controls.Add(tooltip);
tooltip.UpdateDisplay(e.Data);
tooltip.Show();
}
But it appears in the background (I can handle it) and, unfortunately, is limited to the window ...
EDIT: Here is what I ended up doing ...
ToolTip, .NET . , " " ( , ). ToolTip , - , , . . .
, ToolTipWindow . Offset, .
internal class ToolTipWindow: Form
{
public Point Offset { get; set;}
internal ToolTipWindow(Control controlToDisplay)
{
FormBorderStyle = FormBorderStyle.None;
TopMost = true;
ShowInTaskbar = false;
Opacity = 0.9;
Width = controlToDisplay.Width;
Height = controlToDisplay.Height;
Controls.Add(controlToDisplay);
controlToDisplay.Show();
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
Location = new Point(MousePosition.X + Offset.X, MousePosition.Y + Offset.Y);
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
if (Visible)
{
Location = new Point(MousePosition.X + Offset.X, MousePosition.Y + Offset.Y);
}
}
}
, MouseHover MouseMove. , " " . MouseMove , " ". , , !
. MouseHover . , ( " " ), , " ", :
#region AddReHoverExperience
[DllImport("user32.dll")]
static extern int TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);
[StructLayout(LayoutKind.Sequential)]
public struct TRACKMOUSEEVENT
{
public UInt32 cbSize;
public UInt32 dwFlags;
public IntPtr hwndTrack;
public UInt32 dwHoverTime;
}
TRACKMOUSEEVENT tme;
private const uint TME_HOVER = 0x1;
protected override void OnMouseHover(EventArgs e)
{
base.OnMouseHover(e);
OnMouseEnter(e);
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
tme = new TRACKMOUSEEVENT
{
hwndTrack = Handle,
dwFlags = TME_HOVER,
dwHoverTime = 500
};
tme.cbSize = (uint)Marshal.SizeOf(tme);
TrackMouseEvent(ref tme);
}
#endregion AddReHoverExperience