0

I am trying to display images in a Panel control (I am using WinForms), however the images are bigger than the panel's maximum size (32767 pixels).

I searched the Internet about the issue, however I only found a few ready solutions I do not understand, therefore do not want to use them.
What and is there a good way around this issue aside from using WPF?

As of now, I am thinking of manually iterating over controls in Panel and changing their location as needed, however, I think it will not be very efficient and ugly.

Sample code to reproduce the problem:

    for (int i = 0; i < 300; i++) {
        PictureBox picbox = new PictureBox();
        picbox.BackColor = Color.Red;
        picbox.Width = 500;
        picbox.Height = 250;
        picbox.Top = i * 500;
        panelDisplay.Controls.Add(picbox);
    }
Murumuru
  • 17
  • 3
  • I am adding images inside the panel and the images cannot be added if they exceed panel's 32767 size limitation, they are simply placed in the end overlaying one another without any errors. – Murumuru Nov 30 '15 at 06:52
  • Yes, but it does not remove the limit. – Murumuru Nov 30 '15 at 06:56
  • You could manage a table of Panels, each showing a different tile in the big image. – SimpleVar Nov 30 '15 at 07:08
  • So just to make this clear, you are trying to add 300 images x 500 pixels (width) in a single `Panel`, which would then have to be 150'000 pixels wide? – Kjartan Nov 30 '15 at 07:15
  • You may find [this](http://stackoverflow.com/q/8064678/3110834) post helpful. – Reza Aghaei Nov 30 '15 at 07:20
  • @Kjartan, I am trying to load different images one under another in panel. Their total height is more than 32767, so it makes panel unable to display anything over 32767 pixels. – Murumuru Nov 30 '15 at 07:27
  • @Reza Aghaei, I read that post, however the FastAl's solution falls under "ready solutions I do not understand, therefore do not want to use them", and to other suggestion in that post is that I do not understand how to change Paint event. – Murumuru Nov 30 '15 at 07:30
  • Just because you don't understand something, doesn't mean it isn't the correct answer and you shouldn't try to work your way through it. Not understanding something is the first step to growing your knowledge. – Anthony Nov 30 '15 at 12:50

1 Answers1

0

Sounds to me like you might try using more than a single panel.

Very roughly:

 // (5 of these) x (60 pictureboxes in each) = 300 images in all:
 for (int panelNumber = 0; panelNumber < 5; panelNumber++) {
    Panel panel = new Panel();
    panel.Height = 30000; 
    panel.Top = panelNumber * 30000;

    // ...anything else needed to set up the panel...      

    for (int PictureBoxNr = 0; PictureBoxNr< 60; PictureBoxNr++) {
        PictureBox picbox = new PictureBox();
        picbox.BackColor = Color.Red;
        picbox.Width = 500;
        picbox.Height = 250;
        picbox.Top = PictureBoxNr * 500;
        panel.Controls.Add(picbox);
    }

    outerPanel.Controls.Add(panel);
}
Kjartan
  • 18,591
  • 15
  • 71
  • 96
  • It is a way too, but I do want to use one panel to achieve continous scrolling through all loaded pictures and not manage multiple panels with just part images in them. – Murumuru Nov 30 '15 at 07:40