How do you bridge the form/class gap?

Pretend we have a form and a button on the form. Clicking the button results in a photo appearing. Very simple.

Pretend you want to accomplish this with a PictureHolder() class. Clicking said form button creates an instance of PictureHolder (lets call it yourPictureHolder). yourPictureHolder follows an arbitrary path to a jpeg on your hard drive, retrieves the photo, and has done its job. It 'holds the picture' inside itself.

Now comes time to add yourPictureHolder to the form. Here is the source of my confusion. If the instance is declared in the button.click scope, then you cannot do something like 'Form.Add(yourPictureHolder)' within the button's scope because the button is not aware what state yourPictureHolder is in. Maybe it found and stored the photo, maybe it is still iterating through millions of photos, maybe it cannot find a match. So when the button click executes, the final putting the image on the form has to happen elsewhere in the form. How do you solve this dilemma? And still add to the form?

by ArchieTect via /r/csharp

Leave a Reply