can possible dynamically add picturebox image into RDLC Report C# windows form

NazHim 201 Reputation points
2021-01-22T03:44:55+00:00

hi all

can possible dynamically add picturebox image into RDLC Report C# windows form

best regards

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,838 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2021-01-22T09:32:11.01+00:00

    Hi NazHim-9882,
    You can add picturebox image into RDLC Report by following steps:
    1.Add pictureBox and two button controls into Form1
    2.Add a new form(frmPrint) and then add a Report Viewer to frmPrint form.
    You can install Microsoft RDLC Report for Visual Studio via steps below:
    Go to Visual Studio’s Tools Menu > Extensions and Update > Select Microsoft RDLC Report Designer and Reporting Services Project for the Visual Studio.
    59581-1222.png
    After installing, you have to restart the Visual Studio.
    Then you will see that Report and Report Wizard is now available in the Visual Studio.
    Right click the project name->Add-> New item->Report
    59564-122222.png
    Then design your report as below.
    59575-13.png
    More details you can refer to this document.
    3.Add code to handle Form1 form:

    public partial class Form1 : Form  
    {  
        public Form1()  
        {  
            InitializeComponent();  
        }  
        string imageUrl = null;  
        private void button1_Click(object sender, EventArgs e)  
        {  
            //Select an image, then display to the picturebox control  
            using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "JPEG|*.jpg" })  
            {  
                if (ofd.ShowDialog() == DialogResult.OK)  
                {  
                    imageUrl = ofd.FileName;  
                    pictureBox1.Image = Image.FromFile(ofd.FileName);  
                }  
            }  
        }  
    
        private void button2_Click(object sender, EventArgs e)  
        {  
            if (!string.IsNullOrEmpty(imageUrl))  
            {  
                //Open print form  
                using (frmPrint frm = new frmPrint(imageUrl))  
                {  
                    frm.ShowDialog();  
                }  
            }  
        }  
    }  
    

    4.Add code to handle frmPrint form

    public partial class frmPrint : Form  
    {  
        string _imageUrl;  
        public frmPrint(string imageUrl)  
        {  
            InitializeComponent();  
            _imageUrl = imageUrl;  
        }  
    
        private void frmPrint_Load(object sender, EventArgs e)  
        {  
            //Read image from file, then set to report parameter  
            FileInfo fi = new FileInfo(_imageUrl);  
            ReportParameter pName = new ReportParameter("pName", fi.Name);  
            ReportParameter pImageUrl = new ReportParameter("pImageUrl", new Uri(_imageUrl).AbsoluteUri);  
            this.reportViewer1.LocalReport.EnableExternalImages = true;  
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { pName, pImageUrl });  
            this.reportViewer1.RefreshReport();  
    
        }  
    }  
    

    Test result:
    59576-13.gif
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments