Allow scrolling while making a hexagonal montage in C#

[hexagonal montage]

The example Make a hexagonal montage of pictures in C# shows how to make a hexagonal montage similar to the one shown above. I sometimes want to make a montage that is much bigger, and that example doesn’t let you do that. There are two obvious approaches. First, you could draw the montage at one scale and then save it at another. Second, you could let the user scroll the montage.

If you take the first approach, then you would need to convert mouse clicks for the scaled result. This is possible, but more work than the second approach, which is practically trivial. This example simply moves the picGrid PictureBox control that displays the hexagonal montage into a Panel control. That control’s AutoScroll property is set to true, so it automatically displays scroll bars if picGrid is too large to fit.

That’s all there is to it. The picGrid control reports mouse positions in its normal coordinate system even if you have use the panel to move the picture to a new location. The program then uses the mouse clicks to determine which hexagonal area you have clicked.

Download the example to experiment with it. Look at the code and look at the previous post to see additional details.

Download Example   Follow me on Twitter   RSS feed   Donate

About RodStephens

Rod Stephens is a software consultant and author who has written more than 30 books and 250 magazine articles covering C#, Visual Basic, Visual Basic for Applications, Delphi, and Java.
This entry was posted in drawing, graphics, image processing, tools and tagged , , , , , , , , , , , , , , . Bookmark the permalink.