Change cursor and reset it again to default

M

mphanke

Hi,

I have a snippet which makes me go mad!

The clip region of the Cursor is set correctly, but I can't reset it
anymore afterwards! This really drives me nuts, because I don't
understand what is exactly happening at thsi point.

Can anybody tell me what is wrong with this:

void OnMouseClick(Object * sender, MouseEventArgs * mea)
{
if(mea->Button == MouseButtons::Left)
{
m_bLeft = !m_bLeft;
if(m_bLeft)
{
Cursor::Current->Clip =
Rectangle(m_PicBox->PointToScreen(Point(m_PicBox->ClientRectangle.Left,
m_PicBox->ClientRectangle.Top)), m_PicBox->Size);
}
else
{
Cursor::Current = Cursors::Default;
}
}
}


Thanks,

Martin
 
G

Gary Chang

Hi Martin,

I tested your code snippet in a WinForm MC++ project, the following line:
Cursor::Current = Cursors::Default;
seems never been called, it appears the cursor had already been
trapped/beloned by the picture box(m_PicBox) just after you click the left
button of the mouse first time, you cannot trap it in the original function
again.

So I modify the code as following:
....
System::Void Form1_MouseUp(System::Object* sender,
System::Windows::Forms::MouseEventArgs* mea)
{
if(mea->Button == MouseButtons::Left){
Cursor::Current->Clip =
Rectangle(m_PicBox->PointToScreen(Point(m_PicBox->ClientRectangle.Left,
m_PicBox->ClientRectangle.Top)), m_PicBox->Size);
}

}

System::Void m_PicBox_MouseUp(System::Object* sender,
System::Windows::Forms::MouseEventArgs* mea)
{
if(mea->Button == MouseButtons::Left){
this->Cursor = new
System::Windows::Forms::Cursor(Cursor::Current->Handle);
Cursor::Clip = Rectangle(this->Location, this->Size);
}
}
....


Wish it helps!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
M

mphanke

Hi Gary,

thanks for your help! I haven't had time to implement this at the
moment, but I will tomorrow.. I will give you feedback then. Do you have
any idea why this behaviour is?

Martin
 
M

mphanke

Hi Gary,

okay, I figured it out! The problem was I was changing the cursor on the
MouseDown event - this does not work...

Thanks alot for your support!

Martin

Snippet for whoever is interested:

void OnMouseUp(Object * sender, MouseEventArgs * mea)
{
if(mea->Button == MouseButtons::Left)
{
m_bLeft = !m_bLeft;
if(m_bLeft)
{
m_rectClip = Rectangle(Cursor::Current->Clip);
Cursor::Current->Clip =
Rectangle(m_PicBox->PointToScreen(Point(m_PicBox->ClientRectangle.Left,
m_PicBox->ClientRectangle.Top)), m_PicBox->Size);
}
else
{
m_ParentForm->Cursor = new
System::Windows::Forms::Cursor(Cursor::Current->Handle);
Cursor::Clip = Rectangle(m_rectClip);
}
}
}
 
G

Gary Chang

Hi Martin,

Thanks for your response and I am glad to know you got the solution!


Good Luck!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 

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