locked
How to make mouse cursor tracking line on picturebox without disturbing the image in the picturebox? RRS feed

  • Question

  • This is my first time working in visual studio ,previously i made a gui on ubuntu with qt but now have create the same in visual studio.I have a picturebox inwhich i am displaying a continuous feed from a camera.

    Now i want that whenever i move my cusor anywhere on the picturebox it draws a vertical and horizontal line across the picturebox with mouse cursor as intersection without effecting the feed image in the picturebox and draw a rectangle for ROI again without effecting the image in picture box.

    QT result is given below:


    I tried graphic approach but it did'nt gave me required result

     
    Pen^ pen1x = gcnew Pen(Color::Black);
    		 Graphics^ g_cam1_cal;
    		private: System::Void cam1_calib_imagebox_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
    			if (!g_cam1_cal)
    				g_cam1_cal = cam1_calib_imagebox->CreateGraphics();
    			g_cam1_cal->Clear(Color::Empty);
    			g_cam1_cal->DrawLine(pen1x, e->X, 0, e->X, cam1_calib_imagebox->Height);
    
    
    

    Result:

    when cursor was moved 

    Wednesday, April 18, 2018 11:23 AM

All replies

  • Hi victor1765,

    You need to refresh the pictureBox after clear the graphic object:

            Pen^ pen1x = gcnew Pen(Color::Black);
            Graphics^ g_cam1_cal;
    		private: System::Void cam1_calib_imagebox_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)
            {
                if (!g_cam1_cal)
                    g_cam1_cal = cam1_calib_imagebox->CreateGraphics();
                g_cam1_cal->Clear(Color::Empty);
    
                cam1_calib_imagebox.Refresh();
                //cam1_calib_imagebox.Invalidate();//or
    
                g_cam1_cal->DrawLine(pen1x, e->X, 0, e->X, cam1_calib_imagebox->Height);
            }

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 19, 2018 7:01 AM
  • Hi victor1765,

    Have you solved this problem now?

    I think the above reply can provide you with a solution, have you tried it?

    If so, hope you can close this thread by marking the reply as answer as this will help others looking for the same or similar issues down the road.

    Best Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 23, 2018 7:00 AM