Click here to Skip to main content
15,889,034 members
Home / Discussions / C#
   

C#

 
AnswerRe: Notification App Architecture Pin
Mark Salsbery10-May-11 10:12
Mark Salsbery10-May-11 10:12 
GeneralRe: Notification App Architecture Pin
Joshi, Rushikesh11-May-11 3:22
professionalJoshi, Rushikesh11-May-11 3:22 
QuestionGenerate DataSet Table Code Pin
Member 342693610-May-11 5:45
Member 342693610-May-11 5:45 
AnswerRe: Generate DataSet Table Code Pin
Luc Pattyn10-May-11 6:07
sitebuilderLuc Pattyn10-May-11 6:07 
GeneralRe: Generate DataSet Table Code Pin
Member 342693610-May-11 7:11
Member 342693610-May-11 7:11 
AnswerRe: Generate DataSet Table Code Pin
Luc Pattyn10-May-11 7:17
sitebuilderLuc Pattyn10-May-11 7:17 
AnswerRe: Generate DataSet Table Code Pin
PIEBALDconsult10-May-11 14:57
mvePIEBALDconsult10-May-11 14:57 
QuestionSet cursor position without firing MouseMove event [modified] Pin
BHillam10-May-11 2:34
BHillam10-May-11 2:34 
I'm building an application with a 3D render window in the middle of my main form. When the user holds the right mouse button, the cursor is hidden and the mouse is instead used to control the camera within the 3D window. The problem with this is that whilst the cursor is hidden, the mouse is still moving beyond the edge of my window, and eventually I will stop receiving MouseMove events. For this reason I need to set the cursor to it's previous position after handling the MouseMove event.

private void onMouseMove(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        prevMousePos = currMousePos;
        currMousePos = e.Location;

        Point delta = currMousePos - prevMousePos;

        //Do stuff with delta...

        Cursor.Position = prevMousePos;    //Problem!
    }
}


This won't work because changing the cursor position will cause more MouseMove events to be fired. I thought perhaps I could unsubscribe from the MouseMove event before setting the cursor position, and then resubscribe.

this.panel_RenderWindow.MouseMove -= this.onMouseMove;
Cursor.Position = prevMousePos;
this.panel_RenderWindow.MouseMove += new System.Windows.Forms.MouseEventHandler(this.onMouseMove);


The problem is this doesn't seem to be working correctly. I still get MouseMove events generated from moving the cursor programatically. I have a feeling I'm not unsubscribing the handler correctly. I would check this in the debugger, but I'm unable to find the event in the debugger.

Am I unsubscribing the event correctly, and if I am, is there a reason that this isn't working? Is there a better way to achieve this?

Note: a side-effect of the recursive MouseMove events is that the cursor moves until it gets to the top-left corner of the screen, at which point no further events are generated because the mouse can move no further.

modified on Tuesday, May 10, 2011 9:07 AM

AnswerRe: Set cursor position without firing MouseMove event Pin
Shameel10-May-11 3:00
professionalShameel10-May-11 3:00 
GeneralRe: Set cursor position without firing MouseMove event Pin
BHillam10-May-11 3:06
BHillam10-May-11 3:06 
AnswerRe: Set cursor position without firing MouseMove event Pin
Luc Pattyn10-May-11 3:29
sitebuilderLuc Pattyn10-May-11 3:29 
GeneralRe: Set cursor position without firing MouseMove event Pin
BHillam10-May-11 3:58
BHillam10-May-11 3:58 
AnswerRe: Set cursor position without firing MouseMove event Pin
Luc Pattyn10-May-11 4:37
sitebuilderLuc Pattyn10-May-11 4:37 
AnswerRe: Set cursor position without firing MouseMove event [modified] Pin
BHillam10-May-11 5:30
BHillam10-May-11 5:30 
GeneralRe: Set cursor position without firing MouseMove event Pin
Mark Salsbery10-May-11 9:59
Mark Salsbery10-May-11 9:59 
GeneralRe: Set cursor position without firing MouseMove event [modified] Pin
BHillam10-May-11 15:06
BHillam10-May-11 15:06 
GeneralRe: Set cursor position without firing MouseMove event Pin
Mark Salsbery10-May-11 16:39
Mark Salsbery10-May-11 16:39 
QuestionWhat is the best way(s) to send strings from java app to .net app? Pin
CodeGust10-May-11 2:21
CodeGust10-May-11 2:21 
AnswerRe: What is the best way(s) to send strings from java app to .net app? Pin
Groulien10-May-11 2:35
Groulien10-May-11 2:35 
GeneralRe: What is the best way(s) to send strings from java app to .net app? Pin
CodeGust10-May-11 3:39
CodeGust10-May-11 3:39 
AnswerRe: What is the best way(s) to send strings from java app to .net app? Pin
Wayne Gaylard10-May-11 2:44
professionalWayne Gaylard10-May-11 2:44 
GeneralRe: What is the best way(s) to send strings from java app to .net app? Pin
CodeGust10-May-11 3:41
CodeGust10-May-11 3:41 
AnswerRe: What is the best way(s) to send strings from java app to .net app? Pin
jschell10-May-11 12:14
jschell10-May-11 12:14 
GeneralRe: What is the best way(s) to send strings from java app to .net app? Pin
CodeGust10-May-11 12:31
CodeGust10-May-11 12:31 
GeneralRe: What is the best way(s) to send strings from java app to .net app? Pin
jschell11-May-11 8:04
jschell11-May-11 8:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.