Help - Search - Members - Calendar
Full Version: Setting A Mouse Curcer In C#?
BleepingComputer.com > Software > Programming
   
Wolfy87
I am making a shooting game...yada yada yada...for more of that look at my other poasts lol but anyway im trying to assign a curcer to a form...and i just cant do it due to me being quite a beginer but if somone could help that would be great.
So far this is what i have \/ \/ \/

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

But all of the directory is underligned with blue so what am i doing wrong...
Also how would i implement this peice of code to generate a random number within the parameters set \/ \/ \/

int minimumValue=0;
int maximumValue=5;
Random rNum = new Random();
int randomNumber= rNum.Next(minimumValue,maximumValue);

I dont have a clue how it works?... wacko.gif
Wolfy87
Groovicus Please save me! can you just help me out this one last time...Please? mellow.gif
Ryan 3000
See Is It Just Me Or Is C# Random Terrible? for what I said about the random.
Wolfy87
HOws that got to have anything to do with random XD
NiJor
QUOTE(Wolfy87 @ Aug 16 2008, 05:40 PM) *
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

But all of the directory is underligned with blue so what am i doing wrong...


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 !
}


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:
CODE
Cursor = ("C:\\Documents and Settings\\Oliver C\\Desktop\\Programing\\Projects\\VRange\\0,CD.cur");

Or
CODE
Cursor = (@"C:\Documents and Settings\Oliver C\Desktop\Programing\Projects\VRange\0,CD.cur");


Also I noticed the comma in the path at \0,CD.cur this might cause a problem!

QUOTE(Wolfy87 @ Aug 16 2008, 05:40 PM) *
Also how would i implement this peice of code to generate a random number within the parameters set \/ \/ \/

int minimumValue=0;
int maximumValue=5;
Random rNum = new Random();
int randomNumber= rNum.Next(minimumValue,maximumValue);

I don't have a clue how it works?... wacko.gif


For more information on using the Random functionality in C# I suggest you to read the following:
C# Corner, Random Number
Microsoft, Random Function

I hope this helps you, I'm not 100% sure on the included code since I couldn't check it on this computer.
Wolfy87
Thankyou NiJor thumbup.gif some brilliant advice, thankyou so much.
I tryed it and it worked this time.
Thanks NiJor,
Wolfy87.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.