在usercontrol中检索picturebox的图像以形成

时间:2014-07-20 19:55:49

标签: c# winforms picturebox

的UserControl1

private string lastName;    

public string LastName
{
    get { return lastName; }
    set
    {
        lastName = value;
        label1.Text = value;
    }
}

表格

public void Gerar_codigo_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    SqlCommand cm = new SqlCommand("SELECT  tblCategory.Categoryname, tblProduct.Productname,tblProduct.Sinopse FROM tblCategory INNER JOIN tblProduct ON tblCategory.Categoryid = tblProduct.Categoryid where tblCategory.Categoryname= '" + btn.Text + "'", cn);

    try
    {
        SqlDataReader dr = cm.ExecuteReader();

        flowLayoutPanel2.Controls.Clear();
        flowLayoutPanel2.Update();
        while (dr.Read())     
        {
            UserControl1 user = new UserControl1();
            user.Nnovo  = (string)dr["Productname"].ToString();///Adds the values ​​of the database in label1 the usercontrol

            flowLayoutPanel2.Controls.Add(user);//Load usercontrol1 in flowlayoutpanel
            flowLayoutPanel2.Update();

        } dr.Close();           
    }

    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
        Application.ExitThread();
    }

}

在我的UserControllabel1picturebox1

我设置了Label但是如何设置PictureBox以表单形式加载图片?

帮帮我?

1 个答案:

答案 0 :(得分:0)

将图像读取到字节数组,创建它的位图并设置为picturebox1的图像。