Click here to Skip to main content
16,019,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i change the image of picturebox in from1 when i click the button in from 2.
In from2 i have created a bitmap image.When i click the button in from2.It will redirect the from1 and save the bitmap image in the picturebox of from1.
Posted
Comments
BillWoodruff 20-Apr-15 5:22am    
Is Form1 the "Main Form" of a WinForm Application ? Form1 creates Form2 ?
Divakard3 20-Apr-15 7:31am    
actually i have a two forms..In second form i have create a bitmap images..when i click the button in form2..it redirect to first form and load the bitmap image in picturebox of first form

1 solution

//globally define variable on form2

C#
public static Image image;


//form2 create an image
C#
void CreateBitmap()
        {
            System.Drawing.Bitmap flag = new System.Drawing.Bitmap(50, 50);
            for (int x = 0; x < flag.Height; ++x)
                for (int y = 0; y < flag.Width; ++y)
                    flag.SetPixel(x, y, Color.White);
            for (int x = 0; x < flag.Height; ++x)
                flag.SetPixel(x, x, Color.Red);
            image = flag;
            pictureBox1.Image = flag;
        }


//than on button click call createbitmap method and redirect it to form1

C#
private void button1_Click(object sender, EventArgs e)
        {

            CreateBitmap();
            Form1 f1 = new Form1();
            f1.Show();
        }



paste below code on form1 constructor

C#
pictureBox1.Image = Form2.image;
 
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