Loading alot of images, don't want to see the load process...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    #1

    Loading alot of images, don't want to see the load process...

    In my project I have a loading method for 132 PictureBoxs, and will probably load 70-90 images in those boxes based on user selection. There is no error in my loading method. But I have tried to hide all the picture boxes during load time, because I don't like how it looks as they load.

    I have all 132 PB's inside panels, which are hidden at first, and are shown at the end of the method, and I also use Suspend / ResumeLayout to maybe not show them while my method is loading each Image from local folders... But the show at the end of the method seems to be done first then the loop starts, and the Layout functions don't do anything either. I have tried an IF statement within the FOR statement to show the panels at the end of the loop, doesn't work either.

    Basicly, I need this: Keep the panels hidden until the image loading is done. But I haven't figured out how to do this... The show portion of the method seems to always be ran first before the loop starts despite being at the end of the method...

    Any suggestions?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Let's see the actual routine and then maybe we can guide you as to where you went wrong.

    Comment

    • Samishii23
      New Member
      • Sep 2009
      • 246

      #3
      Code:
      void Load() {
      	this.SuspendLayout();
      	for (int i = 0; i < TD.Pts.Count(); i++) {
      		if (TD.Pts[i] == 0) {
      			TIcon[i].Enabled = false;
      			TIcon[i].Visible = false;
      			}
      		else {
      			TIcon[i].Enabled = true;
      			TIcon[i].Visible = true;
      			try {
      				TIcon[i].Image = gi(TD.Icon[i], 1);
      				}
      			catch (Exception EX) {
      				TIcon[i].Image = null;
      				TIcon[i].BorderStyle = BorderStyle.Fixed3D;
      				TIcon[i].BackColor = Color.Black;
      				}
      			}
      		}
      
      	this.ResumeLayout();
      
      	for (int i = 0; i < 3; i++) {
      		TTree[i].Visible = true;
      		}
      	}
      TIcon[] is the PictureBox array.
      TTree[] are the Panels which the PictureBoxs are inside.

      The Panels appear to get shown first before all the Images of each of PictureBox's Images are set.

      gi() is just a method to get the image location based on user settings.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Basicly, I need this: Keep the panels hidden until the image loading is done.
        There is no image loading taking place in the code you have provided.

        Where are you loading the images into your 130+ pictureboxes?

        Comment

        • Samishii23
          New Member
          • Sep 2009
          • 246

          #5
          This loads the images...
          Code:
          TIcon[i].Image = gi(TD.Icon[i], 1);
          This is the gi() method...
          Code:
          public Bitmap gi(string f, int t) {
          	// TODO: Integrate MPQ / BLP file integration based on user prefrences
          	switch (t) {
          		default: return null;
          		case 0: return new Bitmap(Settings[19] + f + ".jpg"); // Tree BG Files
          		case 1: return new Bitmap(Settings[1] + f + ".png"); // Icons
          		}
          	}
          Sorry. Was in a hurry to leave home at the time, forgot to include the gi().

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Suspendlayout is going to do nothing for you because the layout is already completed. It was *done* before the Load() event was ever raised.

            You said the pictureboxes are on a Panel, and that panel is set to visible = false. Is that right?

            If that is so, then where are you setting the panel visible to true when you are done? Since I can see no place where you are turning the panel to visible, I am doubting that you ever have it be not visible.

            Comment

            • Samishii23
              New Member
              • Sep 2009
              • 246

              #7
              Code:
              for (int i = 0; i < 3; i++) {
                       TTree[i].Visible = true;
                       }
              These are the panels. When the program is initialized, the three panels are initilized, and never shown to the user. This is done within the main program load, and within the first SuspendLayout call. So I know they are hidden before the PictureBox load.

              The PB's are within the Panels Controls. Easier to show 3 panels then 132 individual PB's. I hope thats how it came off my earlier comments, sorry if it didn't

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                Why not just set their visible property to false in the designer? That why you know it is done before any of your code runs.

                Here's another good test: In the designer set the panel back color to something odd - like blue. If the panel really is not visible then it won't matter. Just before you set the visible to true, set the color back back to .Control

                If at any time you see a blue panel, then you know it is being set to visible earlier than you thought.

                Comment

                • Samishii23
                  New Member
                  • Sep 2009
                  • 246

                  #9
                  I don't use the designer anymore. I'll run a test project though, and see what happens.

                  Comment

                  • tlhintoq
                    Recognized Expert Specialist
                    • Mar 2008
                    • 3532

                    #10
                    OK. Wherever you actually created the panel for the first time... Did you set it to .Visible = false?

                    The simple idea here is that if you are seeing the pictureboxes load images then you haven't made them not visible.

                    Comment

                    • Samishii23
                      New Member
                      • Sep 2009
                      • 246

                      #11
                      OK. Wherever you actually created the panel for the first time... Did you set it to .Visible = false?
                      Of course tlhintoq. I mentioned this above. Though it appears I have been vague yet again. Sorry.

                      This is my panel loop:
                      Code:
                      TTree[i] = new Panel();
                      TTree[i].Size = new Size(s2i(Settings[10]), s2i(Settings[9]));
                      TTree[i].Name = "Tree." + i2s(i);
                      TTree[i].BackColor = Color.Transparent;
                      TTree[i].BorderStyle = BorderStyle.None;
                      TTree[i].BackgroundImageLayout = ImageLayout.Center;
                      TTree[i].Visible = false;
                      TTree[i].Location = new Point(s2i(TreeX[i]),s2i(Settings[7]));
                      this.Controls.Add(TTree[i]);
                      s2i() is just a string to int32 converter.

                      Comment

                      • tlhintoq
                        Recognized Expert Specialist
                        • Mar 2008
                        • 3532

                        #12
                        Code:
                        TTree[i].BackColor = Color.Transparent;
                        So did you try my suggestion of making the backcolor something obvious like Blue, then change it to Transparent when you are done loading and make it .Visible = true? As a means of determining if it was becoming visible earlier than you thought? If you see blue before you are done loading then you know you are turning it visible early.

                        Comment

                        • Samishii23
                          New Member
                          • Sep 2009
                          • 246

                          #13
                          I did as you suggested.

                          I changed the .BGColor to something noticable.

                          The result was different then I would have thought. When I changed the BGColor to anything but Transparent, the method run as I would have thought originally. All the PB's were loaded then displayed. Load time was probably a second rather then 2-3 for when you would watch each PB load individually.

                          It seems that when the BGColor is transparent it causes that Visibility issue... Seems weird. But now I know this. I'll just keep the Panels a solid color. Thank you for your help.

                          Comment

                          • tlhintoq
                            Recognized Expert Specialist
                            • Mar 2008
                            • 3532

                            #14
                            That's because in reality the panels aren't really transparent. They exactly clone the data below them to mimic being transparent. And do to that, they have to be visible. Color.Transpare nt in the .NET framework is a lie.

                            It also explains the reduction in processing time. When it was transparant and having to mimic the contents below it had to constantly re-process every time a new PB load occured. When it stopped having to do all that hidden processing it stopped taking so long.

                            Comment

                            • Samishii23
                              New Member
                              • Sep 2009
                              • 246

                              #15
                              So thats what Transparency does... Huh, interesting. Well thanks for the insight. :)

                              Comment

                              Working...