clicking on the image in one form open another form with same image
hi i have two forms form1 and form2 i have data grid view in form 1 filling with the data comin开发者_如何学Gog from database has two columns product image and product name
i am using winforms with c#
I want to click the one of the column in datagridview(particularly Image column) another form(form2) will be open and in form 2 the image will be displayed in that form
any idea how to implement this....
many thanks ...
Get the image name or url out of the gridview and pass it to the second form as a parameter. Then in the second form, get the image name you just passed and fill your picturebox (or something else) with the picture you want using the picture name
Onclick
event of image of the gridview show the second form then assign Image
property of its picturebox with the image of gridview
Form2 f2 = new Form2();
f2.Show();
//Here I am not using GridView
f2.pictureBox1.Image= this.pictureBox1.Image;
Note you should set the modifier of picture box in second form to public
This is most Suitable way for passing image to another form
Following Code insert in to Form1
Form2 fm = new Form2(this.picEncode.Image);
fm.Show();
Following Code insert in to Form2
public partial class Form2 : Form
{
Image picQr;
public Form2(Image qrCodeimage)
{
InitializeComponent();
picQr = qrCodeimage;
}
private void Form2_Load(object sender, EventArgs e)
{
pictureBox1.Image = picQr;
}
}
精彩评论