Search code examples
.netwinformsc++-clisystem.drawing

Convert Point to Point^


I'm trying move my form with using left mouse button. I have this:

if(e->Button == Windows::Forms::MouseButtons::Left)
{
    Point^ mousePos = gcnew Point();
    mousePos = Control::MousePosition;
        mousePos->Offset(mouse_offset->X,mouse_offset->Y);
    Location = mousePos;
}

Code seems ok, but Visual returning error:

error C2664: 'void System::Windows::Forms::Control::Location::set(System::Drawing::Point)' : cannot convert parameter 1 from 'System::Drawing::Point ^' to 'System::Drawing::Point'

I don't understand - I created variable mousePos as a Point^. Do you have any idea what's wrong?


Solution

  • The problem is that the method expects a Point whereas you are passing it a Point ^ (managed pointer to Point - weeee, too much "point"s here...).