a question about objects

  • Thread starter Thread starter gael
  • Start date Start date
G

gael

I have a windows form MyForm and a picturebox PicBox on
it.

I need a funtion that return MyForm as object.(the
parameter is PicBox.

Is it possible to do that? (To get the name of a parent
class from a child class such as PictureBox)?
 
object parentForm = PicBox.Parent; ----->doesnt work

when i try to do this, the type of parentForm is
System.Windows.Forms.Control but i want it to be
System.Windows.Forms.Form.

I just want a funtion that return the form in which there
is my pictureBox.
 
You have to cast the value as Form. Forms inherit from the Control class,
and the Parent property is type Control, but can be a Form.
You Might also have a nested control (control inside a control).
In that case try PicBox.TopLevelControl instead of PicBox.Parent

-Rob Teixeira [MVP]
 
I finally found a solution.
The function i was looknig for is: PicBox.FindForm

It returns the form that the control is on.

Thanks a lot anyway.
 
Back
Top