none
Form application with Panel and PictureBox controls: Panel.Clear() does NOT clean. (in C#)

    Question

  • I have been developing a Windows Form application with a Panel and many PictureBox controls. PictureBox controls are created dynamically in the Panel control. The initial display works fine, say with 100 PictureBoxes in the Panel control. Then, the Panel control is cleared by "this.panel.CLear()", for the next display, say new 50 images in the PictureBoxes.

    The current situation is that the second display (with new 50 images) seem to be completed AFTER the first 100 images, although the first 100 images are cleaned. This means that the first area where the first 100 images displayed is blank, and the new 50 images are displayed after the blank/white area.

    My question is how to display the new images at the beginning of the Panel control.

    Thanks

    • Moved by CoolDadTxMVP Thursday, October 14, 2010 1:19 PM Winforms related (From:Visual C# IDE)
    Thursday, October 14, 2010 11:00 AM

Answers

  • Hi DFusionTF,

     

    > The current situation is that the second display (with new 50 images) seem to be completed AFTER the first 100 images, although the first 100 images are cleaned.

     

    I would like to know how you calculate the location of these pictureboxes. After removing the previous picturebox, do you set the location correctly for newly added picturebox? If you want to check whether the pictureboxes have been removed, you can use panel1.Controls.Count. You can also call panel1.Controls.Clear(); to remove all controls in the Panel.

     

    Sincerely,

    Kira Qian

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by Kira Qian Monday, October 18, 2010 3:13 AM
    Friday, October 15, 2010 6:21 AM

All replies

  • Hi DFusionTF,

     

    > The current situation is that the second display (with new 50 images) seem to be completed AFTER the first 100 images, although the first 100 images are cleaned.

     

    I would like to know how you calculate the location of these pictureboxes. After removing the previous picturebox, do you set the location correctly for newly added picturebox? If you want to check whether the pictureboxes have been removed, you can use panel1.Controls.Count. You can also call panel1.Controls.Clear(); to remove all controls in the Panel.

     

    Sincerely,

    Kira Qian

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by Kira Qian Monday, October 18, 2010 3:13 AM
    Friday, October 15, 2010 6:21 AM
  • Use two panels one for the first 100 and one for the second 50
    Success
    Cor
    Friday, October 15, 2010 7:13 AM
  • Hi Kira,

    It seems to have a wrong starting POINT for the second 50 pictures.

    Thank you very much your advice. Takashi Fukuda

    Sunday, October 17, 2010 11:13 PM
  • Hi Kira,

    It was confirmed that the starting point of PictureBoxes was not reset for the second 50 images. Your advice solved the problem.

    Thank you very much, Takashi Fukuda

    Sunday, October 17, 2010 11:42 PM
  • Are you calling Panel.PerformLayout after adding new controls?  Showing some code that illustrates how you're adding and removing the PictureBox controls from the panel would be very helpful!

     

     


    -cd Mark the best replies as answers!
    Sunday, October 17, 2010 11:44 PM