accessing picture box on childform, c#
hi i have childform and parent form I want to show picture in picturebox in childform at run time. How can I access it from parent form. e.g. i can change nackground of childform from parentform
it works childForm.BackgroundImage = Image.FromFile(str[2]);
but how can i access picturebox.
i tried like this
public PictureBox picturebox1
{
get
{
return picturebox1;
}
set
{
picturebox1 = value;
}
}
and then from parentform
childForm.picturebox1.Image = Image.From开发者_StackOverflow中文版File(str[2]);
but got error.
An unhandled exception of type 'System.StackOverflowException' occurred in Unknown Module. anyhint regards,
This generates a StackOverflowException. Your property getter is returning itself and the property setter is assigning itself. Give it a different name. Furthermore, you want to assign the image, not the control. Fix:
public Image Image
{
get { return pictureBox1.Image; }
set {
if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
pictureBox1.Image = value;
}
}
Next time you ask a question like this, be sure to document the kind of error you see. Exceptions are meant to help you. Or to help us help you.
精彩评论