1
votes

How can i move scrollbars of picturebox when a button is pressed?

I have flowLayoutPanel (Dock: none, AutoSize: false, AutoScroll: true) and i placed on it a PictureBox (Dock: none, SizeMode: AutoSize). I loaded a large image (9000x6315px) into PictureBox so scrollbars are visible and allow me to scroll map. But.. only with mouse. How can i scroll a PictureBox using a code, when a button is pressed?

Problem is BETTER visible in this video on youtube (duration 3mins) and will let you better understand what i mean:

https://youtu.be/3Haqzsyn_zE

In Embarcadero Rad Studio i could write something like this:

ScrollBox1->HorzScrollBar->Position=500;  
ScrollBox1->VertScrollBar->Position=500;

Is it possible in VS?

Thank you!

1

1 Answers

0
votes

Add a temporary button to your form, with this code (inserting the name of your FlowLayoutPanel):

Console.WriteLine(flowLayoutPanel1.AutoScrollPosition.ToString());

Scroll your zoomed map to the position you want it to be in and click the button.

Example output:

{X=-146,Y=-164}

Whatever those values are, you want to store the opposite of them. Repeat the process and write down all the positions you need.

Now you can set the AutoScrollPosition of your FlowLayoutPanel to any of those points, and it will scroll there. For instance, if that was the desired point for your "B1" button:

private void B1_Click(object sender, EventArgs e)
{
    Point pt = new Point(146, 164);
    flowLayoutPanel1.AutoScrollPosition = pt;
}