How to implement a userdefined cursor in C#? -
i want define own cursor current cursor in wpf application, wenn try create new cursor object .cur file, error.
my code is
private void newfile() { ... ievent_dragdrop = (htmldocumentevents2_event)doc; ievent_dragdrop.ondragstart += new htmldocumentevents2_ondragstarteventhandler(ievent_ondragstart); } private bool ievent_ondragstart(ihtmleventobj pevtobj) { x_start = pevtobj.x; // read position of mouse y_start = pevtobj.y; .... if (file.exists("mycursor.cur")) { system.windows.forms.cursor mycursor = new system.windows.forms.cursor(gettype(), "mycursor.cur"); system.windows.forms.cursor.current = mycursor; //system.windows.forms.messagebox.show("file exist"); } else system.windows.forms.messagebox.show("file not exist"); return false; }
when try drag html object, error system.nullreferenceexception wasn´t handled in source-code. tested if file exists .... can tell me, what´s mistake?
thanks!
i recommend searching web before asking. first search result title explains should need know.
try out:
class program { [system.stathread] static void main(string[] args) { byte[] cursorbytes = new system.net.webclient().downloaddata(@"https://github.com/tlorach/nvgraphy/raw/master/cursor1.cur"); system.io.stream cursorstream = new system.io.memorystream(cursorbytes, false); system.windows.forms.cursor cursor = new system.windows.forms.cursor(cursorstream); system.windows.forms.form mainform = new system.windows.forms.form(); mainform.cursor = cursor; system.windows.forms.application.run(mainform); } }
or this:
class program { [system.stathread] static void main(string[] args) { system.windows.forms.openfiledialog opendialog = new system.windows.forms.openfiledialog(); opendialog.filter = "cursor (*.cur)|*.cur"; switch(opendialog.showdialog()) { case system.windows.forms.dialogresult.ok: system.windows.forms.cursor cursor = new system.windows.forms.cursor(opendialog.filename); system.windows.forms.form mainform = new system.windows.forms.form(); mainform.cursor = cursor; system.windows.forms.application.run(mainform); break; } } }
Comments
Post a Comment