0

I am able to get the width and length of the picturebox1, but i cant find the correct code to get the x and y position of the picturebox1, i have already tried following code;

job = new ScreenCaptureJob();
System.Drawing.Size area = SystemInformation.WorkingArea.Size;
Rectangle captureRect = new Rectangle(0, 0, pictureBox1.ClientSize.Width -(pictureBox1.ClientSize.Width % 4), pictureBox1.ClientSize.Height - (pictureBox1.ClientSize.Height % 4));

I used screencapturejob from MEE to do the recording process.

Tuğca Eker
  • 1,493
  • 13
  • 20
Happy
  • 1
  • 1
  • i use this code from the link but theres message : the name picturebox1 doesnt exist in the current context, do you have any ide how to fix this ? – Happy Jan 21 '17 at 16:00
  • I don't know how exactly you use `picturebox1` and where it is defined, because you didn't show us that. But in any case this error is quite generic and boils down to an attempt to use variable/field in a scope that is unaware of that variable/field - http://stackoverflow.com/questions/18233630/variable-does-not-exist-in-the-current-context. – Eugene Podskal Jan 21 '17 at 19:06

1 Answers1

0

Use something like:

Point pt = pictureBox1.PointToScreen(new Point(0, 0));
Rectangle captureRect = new Rectangle(pt.X, pt.Y, pictureBox1.ClientSize.Width - (pictureBox1.ClientSize.Width % 4), pictureBox1.ClientSize.Height - (pictureBox1.ClientSize.Height % 4));
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • i use that code but theres message : the name picturebox1 doesnt exist in the current context, what should i do then ? – Happy Jan 21 '17 at 18:29
  • This code would have to be executed within the Form containing pictureBox1. If this is not the case, then you'd need to **pass** a reference to that PictureBox from the Form to where ever you're attempting to access it. We'd need to see more of your code to better help you. – Idle_Mind Jan 21 '17 at 19:05
  • 1
    Stupid question...did the original code you posted generate that error? Anywhere it worked, the new code should also work. – Idle_Mind Jan 21 '17 at 19:22
  • hey it solved, i try to rewrite the code.. im sorry but im new to this C# programming,, i will try to get better then – Happy Jan 22 '17 at 05:57