I have a tablelayout with 10x10 (columns x rows), I can drop objects into those cells.
I want to add an image (as a background) to that tablelayout that can be scrollable and covers all the table cells, the user can upload any image size.
drag/drop is working, my probleme is: I can't scroll the tablebackgound image eventho i set
private void addImage()
Image img = Image.FromFile(@"C:\Users\c1\Desktop\img_Clean.png");
if (tableLayoutDropZone.BackgroundImage != null) tableLayoutDropZone.BackgroundImage.Dispose();
tableLayoutDropZone.BackgroundImage = img;
tableLayoutDropZone.AutoScrollPosition = Point.Empty;
tableLayoutDropZone.AutoScrollMinSize = new Size(img.Width, img.Height);
You need to do three things:
yourTLP.AutoScroll = true and, of course the
Set a suitable
AutoScrollMinSize; It should have the same size as the image you use as
BackgroundImage, i.e. when the image changes you need to reset the
Paintevent to include this line:
Here is my code to load a new image:
Image img = Image.FromFile(someimagepath); if (yourTLP.BackgroundImage != null) yourTLP.BackgroundImage.Dispose(); yourTLP.BackgroundImage = img; yourTLP.AutoScrollPosition = Point.Empty; yourTLP.AutoScrollMinSize = new Size(img.Width, img.Height);
Note that as the TLP scrolls the controls it holds are scrolled as well!
If you want them to stay fixed you can do this:
Panelwith the very same settings and code
You may want to turn on
DoubleBuffering for smoother scrolling..