Click here to Skip to main content
15,918,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to upload image in the usercontrol that have scroll bars. I need help with adjusting co-ordinates when the scroll position is changed. I am trying to display the selected area of this image zoomed on to the another picture box depending on the co-ordinates of the image when certain area is clicked on the image with in usercontrol.

It works fine if I am working with the top part of the image, but when I scroll down the co-ordinates are no more same.

I need help with selecting the right coordinate even when the scroll position changes.

C#
private void imagePanel1_MouseClick(object sender, MouseEventArgs e)
      {
          if (comboBox1.Items.Count > 0)
          {
           
              // e.X & e.Yare used to get MousePositionX and MousePositionY
              //Rect = new Rectangle(e.X, e.Y, 1200, 100);
              //this.Invalidate();
              // int X2;
              Graphics g = imagePanel1.CreateGraphics();
              g.DrawRectangle(new Pen(Brushes.Black),
              new Rectangle(new Point(e.X, e.Y), new
                  Size(1200, 45)));



}

What I have tried:

I have tried to adjust position
Posted
Updated 27-Aug-16 11:08am
Comments
Philippe Mori 26-Aug-16 16:46pm    
Your question is not clear at all at least for me. I have no idea of what you are trying to do and the problem you get.
Member 12076824 29-Aug-16 10:56am    
I am trying to zoom selected part of image from usercontrol onto pictureBox. It works fine when scroll position is at the top part of the usercontrol, but when I try to scroll to bottom of the image it doesn't works as old coordinates gets assigned to current position of the usercontrol. When usercontrol's scroll position is at top co-orinates are (0,0), but when position is changed to bottom co-ordinaets remains(0,0) from the middle of the image

1 solution

You have to get scroolposition. YourContainer.VerticalScroll.Value for Vertical scroll position and YourContainer.HorizontalScroll.Value for Horizontal scroll values. You can multiple or difference values the your picturebox with this values to accord.
 
Share this answer
 
Comments
an trần 2023 22-Jun-23 4:33am    
11212

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900