Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know how to open a form but how do i edit it when i open it? like there is a picturebox in the other form and i want to change the backcolor of it when its opened

eg

form2 newform2 = new form2();
newform2.show();

// this part here is my preoblem, how do i make it so it will change, like right now its not giving me the option

picturebox1.backcolor = color.green;
Posted

You could overload the Form2 constructor with a version that accepts the desired background color:

C#
public Form2(Color background)
{
    InitializeComponent();
    if (background != null)
    {
        pictureBox1.BackColor = background;
    }
}


and then do this:

Form2 forum2 = new Form2(Colors.Green);
 
Share this answer
 
v2
Hi,

Handle the Load event of form2 in your main form.
Do whatever you want to do with Main form in this method which assigned with handler.

Hope it will help you.

Regards
AR
 
Share this answer
 
C#
form2 newform2 = new form2();
newform2.show();

//here you are changing the background color of a picture box
//stored in THIS form: NOT form2!!
picturebox1.backcolor = color.green;


Did you attend somethign like this?
C#
form2 newform2 = new form2();
newform2.Show();
newform2.picturebox1.BackColor = Color.Green;
 
Share this answer
 
Comments
Ankit Rajput 4-May-11 7:56am    
I think, He wants to change the color picturebox of Main Form from where form2 is opening.
Olivier Levrey 4-May-11 8:02am    
Maybe. Unless he gives more details, we can't really know...
I'd say you have to read about instances and objects again. But for a quick help: Make picturebox1 accessible from outside - (a property on Form2 exposing the PictureBox would be best, but just setting the Modifyer property of your PictureBox to public should do it for you)
After that - try it with Olivier Levrey's Code

form2 newform2 = new form2();
newform2.Show();
newform2.picturebox1.BackColor = Color.Green;


Anyway in a clean solution Form2 would handle this itself (during load, construction, show, etc.) But I think this is not real world code? If you still can't get it done I'll create a complete example for you - just let me know..
 
Share this answer
 
v2
Hi systemerror121,

I think as I understand from your question you need to to change the backcolr of the picturebox in form2 when opening it.

so you can add your code in the constructor of the form2 class or in form2_load event handler as follows :

public Form2()
{
    InitializeComponent();
    picturebox1.backcolor = color.green;
}


or

public void Form2_Load(object sender, EventArgs e)
{
    picturebox1.backcolor = color.green;
}


I hope this help,
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900