Reputation: 1945
I've been trying to get my cursor to be a custom cursor from a .cur file located in a folder in my project as a Resource
. Here's my solution layout:
test_cur.cur's build action is set to Resource
. In my class library is a UserControl
at the top level which is what I want to change the cursor for. Here's the relative code:
public partial class SampleControl: UserControl
{
InitializeComponent();
StreamResourceInfo streamResource = Application.GetResourceStream(new Uri("test_cursor.cur", UriKind.Relative));
Cursor = new Cursor(streamResource.Stream);
}
I've tried a few different variations of the Uri
but I always get an error Cannot locate resource 'test_cursor.cur'
.
Upvotes: 0
Views: 527
Reputation: 1945
I got it working doing the following:
Uri uri = new Uri("pack://application:,,,/SampleClassLibrary;Component/Images/test_cursor.cur");
StreamResourceInfo streamResource = Application.GetResourceStream(uri);
SampleClassLibrary
is the name of the class library project under the solution.
I had to make the Uri
the way it was because the .cur file is a Resource
under a class library and is being hosted in a different project under the same solution
Upvotes: 0
Reputation: 671
The file path is wrong.
StreamResourceInfo streamResource = Application.GetResourceStream(new Uri("Images\\test_cursor.cur", UriKind.Relative));
Cursor = new Cursor(streamResource.Stream);
Upvotes: 1