forum

Home / DeveloperSection / Forums / how to access my form's panel in my class

how to access my form's panel in my class

Mark Devid 1855 18-Dec-2013

I have a form and in the form I have a panel named : mypanel

now I want to write a class and in this class I want to use this:

foreach (Control cont in mypanel.Controls)
        {
            // do sth
        }
but it is impossible, please help me how to access my form's panel in my class
I use this code :
foreach (Control cont in mypanel.Controls)
            {
                if (cont is PictureBox)
                {
                    string path = @"" + Application.StartupPath + "\\Image\\";
                    cont.BackgroundImage = Image.FromFile(path + Rnd.Next(7).ToString() + ".png");
                }
            }

and I have this Error:

"the name 'mypanel' does not Exist in the current context"


c# c# 
Updated on 18-Dec-2013

Can you answer this question?


Answer

1 Answers

Liked By