Problem with SetCapture

D

Developer

Hello,

I'm trying to modify one of the Scribble sample apps (C#) such that the user
can draw w/o holding the mouse button down. That is, the first mouse click
turns on drawing, and the second mouse click turns it off.
In the MouseDownHandler, I set the Capture property:
this.Capture = true;

I put some TRACE output in the MouseMove handler; when the cursor leaves the
mdi child window, it stops getting the mouse messages. I though the Capture
property would make sure the window gets all mouse messages until some other
window captured the mouse.
How can I get the desired behavior? I'm just experimenting with this app;
eventually, I'll be drawing rubber band shapes and I need to have the rubber
band drawing track with the mouse, even when it is outside the client
window.

TIA for any ideas.
 
P

Phil Wright

By default I would guess that the MouseUp will be releasing any capture as
that is the default action that most people would expect. I would override
the MouseUp and after calling the base class implemention recapture the
mouse again.

Phil Wright
Follow my microISV startup at...
http://componentfactory.blogspot.com
 
D

Developer

Thanks, Phil, that makes sense.

Unfortunately, when I do this:
private void MouseUpHandler(Object sender,MouseEventArgs e)
{
//If the current stroke is null, ignore this event
if (currentStroke==null)
return;

base.OnMouseUp(e);
// if we just started drawing, ignore this mouseUp.
if (_drawState == drawState.startDraw) {
System.Diagnostics.Debug.WriteLine("MouseUp _drawState == true;
returning");
_drawState = drawState.isDrawing;
this.Capture = true;
return;
}
// etc.

base.OnMouseUp(e) generates a StackOverflow exception. 'base' should be
System.Windows.Forms.Form...
 
D

Developer

If, instead of doing this:
this.MouseUp += new MouseEventHandler(MouseUpHandler);
:
private void MouseUpHandler(Object sender,MouseEventArgs e)

I handle the MouseUp like this
protected override void OnMouseUp(MouseEventArgs e)
calling
base.OnMouseUp(e)
doesn't crash.

Still don't get the MouseMove messages when the cursor is outside the mdi
child window, though.
 
D

Developer

More info:
protected override void OnMouseMove(MouseEventArgs e)
{
if (this.Capture == false) {
Trace.WriteLineIf(generalSwitch.TraceVerbose, "MouseMove, mouse NOT
Captured");
// etc.
}
}

It appears no matter what I do in OnMouseDown/OnMouseUp, the mouse is not
captured in the OnMouseMove.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top