C
C#2y ago
Lounder

Is it possible to run code only when a hover event occurs in my application? [Answered]

The application shouldn't get in the way of the user. The user should be able to hover over other applications and mine at the same time. The image illustrates this.
2 Replies
Lounder
Lounder2y ago
Solution:
public void OnHoverHide(object? sender, EventArgs e)
{
Point MousePos = GetMousePosition();

Debug.WriteLine($"\n\n#\n\n{MousePos.X}-{MousePos.Y}\n\n#\n");

Point TopLeftWindowPoint = new Point(AppWindow.Left, AppWindow.Top);
Point BottomRightWindowPoint = new Point(AppWindow.Left + AppWindow.Width, AppWindow.Top + AppWindow.Height);

//If mouse isn't over window
if (MousePos.X >= TopLeftWindowPoint.X && MousePos.Y >= TopLeftWindowPoint.Y)
{
if (MousePos.X <= BottomRightWindowPoint.X && MousePos.Y <= BottomRightWindowPoint.Y)
{
BorderContainer.Opacity = 0;
return;
}
}
BorderContainer.Opacity = 1;
}
public void OnHoverHide(object? sender, EventArgs e)
{
Point MousePos = GetMousePosition();

Debug.WriteLine($"\n\n#\n\n{MousePos.X}-{MousePos.Y}\n\n#\n");

Point TopLeftWindowPoint = new Point(AppWindow.Left, AppWindow.Top);
Point BottomRightWindowPoint = new Point(AppWindow.Left + AppWindow.Width, AppWindow.Top + AppWindow.Height);

//If mouse isn't over window
if (MousePos.X >= TopLeftWindowPoint.X && MousePos.Y >= TopLeftWindowPoint.Y)
{
if (MousePos.X <= BottomRightWindowPoint.X && MousePos.Y <= BottomRightWindowPoint.Y)
{
BorderContainer.Opacity = 0;
return;
}
}
BorderContainer.Opacity = 1;
}
Accord
Accord2y ago
✅ This post has been marked as answered!