Hi,@William Liu. Welcome to Microsoft Q&A.
You could set the value directly to display a cursor of type IBeam.
public OverLay()
{
_window.Left = 0;
_window.Top = 0;
_window.WindowState = WindowState.Maximized;
_window.Background = Brushes.Transparent;
_window.WindowStyle = WindowStyle.None;
_window.AllowsTransparency = true;
_window.Topmost = true;
_window.ShowInTaskbar = false;
_window.IsHitTestVisible = true ;
_window.Focusable = false;
var canvas = new Canvas { IsHitTestVisible = true, Focusable = false};
_window.Content = canvas;
var rectangle = new Rectangle
{
Width = 100,
Height = 100,
Stroke = Brushes.Red,
StrokeThickness = 40,
IsHitTestVisible = true,
Cursor= Cursors.IBeam,
Focusable = false,
};
canvas.Children.Add(rectangle);
Canvas.SetLeft(rectangle, (canvas.ActualWidth - rectangle.Width) / 2);
Canvas.SetTop(rectangle, (canvas.ActualHeight - rectangle.Height) / 2);
};
_window.ShowDialog();
}
When you need the current cursor of an application covered by a WPF application, you can refer to the following solution.
Cause analysis:
When the mouse enters a WPF program, the default mouse icon is Arrow.
If you set the entire Window to Brushes.Transparent, then this area does not have the pixels of your program, which means you are not in the WPF program, and the mouse icon is based on the mouse icon outside the program.
But if you set the color in Rectangle, then this area has the pixels of your program, which means you are in the WPF program, and the mouse icon changes to the default Arrow.
Solution:Use the MouseEnter event to set the Cursor of the current control to the mouse icon before entering the current control
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.