Changing A Mouse Cursor using C# Code.
I am developing a new project using C#.
I am trying to assign a curcer to a form...and i just cant do it due to me being quite a beginer but if someone could help that would be great.
So far i have search this code but it is not working,
Code:
Private Sub Game_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Cursor = ("C:\Documents and Settings\Oliver C\Desktop\Programing\Projects\VRange\0,CD.cur")
End Sub
Re: Changing A Mouse Curcer using C# Code.
Code:
Private Sub Game_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Cursor = ("C:\Documents and Settings\Oliver C\Desktop\Programing\Projects\VRange\0,CD.cur")
End Sub
First thing I noticed is that the above stated code is in Visual Basic since it uses Private Sub and End Sub.
So we must change that to C# code,
Code:
private void Game_Load(object sender, EventArgs e)
{
Cursor myCursor = new Cursor(@"C:\Documents and Settings\Oliver C\Desktop\Programing\Projects\VRange\0,CD.cur");
someControl.cursor = myCursor; //Replace someControl !
}
I hope now you will not get any error after using this code.
Re: Changing A Mouse Curcer using C# Code.
When including a path in C# you have to escape the \ character as \\ or you could place an @ in front of the path.
for example:
Cursor = ("C:\\Documents and Settings\\Oliver C\\Desktop\\Programing\\Projects\\VRange\\0,CD.cur");
OR
Cursor = (@"C:\Documents and Settings\Oliver C\Desktop\Programing\Projects\VRange\0,CD.cur");