c# - Changing cursor shape to have the copy cursor shape -
i know when doing drag-drop can like
private void form_dragover(object sender, drageventargs e) { e.effect = dragdropeffects.copy; }
to make cursor have plus image meaning copy. wondering if can when not doing drag-drop (for example when user clicks specific place cursor changes style until user clicks somewhere else). tried using cursor = cursors.<style>
not contain this. ideas ?
this quite difficult unless want display wait cursor. special case, handled application.usewaitcursor property. problem every control affects cursor shape, selected cursor property. textbox example insist on changing shape i-bar.
you ahead wanting between 2 clicks. trickery possible in case, can capture mouse when button clicked cursor shape solely controlled button. hack required when user clicks mouse again, click go same button , not whatever control clicked. needs fixed synthesizing click. sample code gets done:
bool customcursorshown; private void button1_mouseup(object sender, mouseeventargs e) { if (button1.displayrectangle.contains(e.location)) { this.begininvoke(new action(() => { customcursorshown = true; button1.cursor = cursors.help; // change cursor want button1.capture = true; })); } } private void button1_mousedown(object sender, mouseeventargs e) { if (customcursorshown) { var pos = this.pointtoclient(button1.pointtoscreen(e.location)); var ctl = this.getchildatpoint(pos); if (ctl != null && e.button == mousebuttons.left) { // may want alter if special action required // i'm synthesizing mousedown event here... pos = ctl.pointtoclient(button1.pointtoscreen(e.location)); var lp = new intptr(pos.x + pos.y << 16); // note: taking shortcut on wparam here... postmessage(ctl.handle, 0x201, (intptr)1, lp); } } button1.capture = false; } private void button1_mousecapturechanged(object sender, eventargs e) { if (!button1.capture) { customcursorshown = false; button1.cursor = cursors.default; } } [system.runtime.interopservices.dllimport("user32.dll")] private extern static intptr postmessage(intptr hwnd, int msg, intptr wp, intptr lp);
Comments
Post a Comment