OK, let's start with the basics of Event handling.
When an event is raised by (for example) a button click, the system calls the handler method and passes it two parameters:
which is an
which is always derived from
. The former is the class instance that raised the event (the Button the user clicked) and the latter is information about the actual Click.
So in a mouse event like MouseDown, you would get the Control that the user was over when they press the mouse button as the
would be a
instance (which derived from
and contains more info) telling you which button(s) and where on the COntrol it was clicked.
You can't just cast either of those parameters to a "different type" unless they actually started out as that type (or something derived from it) - so
ClassPictureBox = (PictureBox)Sender;
will fail unless sender is a PictureBox.
probably doesn't get called from a PictureBiox event - it's a lot more likely to have a Task, or Thread based object as it's
so that it can "refer back" to that if it needs to report some progress for example. And since that isn;t derived from any Control, you definitely can't try to cast it to a PictureBox.
Your whole code looks like it was thrown together in panic - there isn't a lot there that looks like it was thought about and planned in advance.
Your class can't "show a picturebox" - it's not derived from Control, so it can't display anything, and if it's being executed on a thread other than the main thread it can't access any displayable Controls.
Why are you throwing PictureBoxes around anyway? Why not just pass the Image instead, and cut out the middleman?
Plus, when you call Image.FromFile, the source file is locked by the system so that it can't be accessed again until the Image you created from it has been Disposed - and I'm guessing that that doesn't happen until your app closes!
I'd strongly suggest that you need to throw that code away, sit down and think about exactly what you are trying to do, then plan what you need instead of rushing straight into code = it'll save you a lot of time in the long run!