private void bPaste_Click(object sender, System.EventArgs e)
        {
            // Make sure we have an image on the clipboard
            IDataObject iData = Clipboard.GetDataObject();

            if (iData == null || !iData.GetDataPresent(DataFormats.Bitmap))
            {
                MessageBox.Show(this, "Copy image into clipboard before attempting to paste.", "Image");
                return;
            }

            System.Drawing.Bitmap img = (System.Drawing.Bitmap)iData.GetData(DataFormats.Bitmap);

            // convert the image to the png format and create a base 64	string representation
            string imagedata = GetBase64Image(img);

            img.Dispose();

            if (imagedata == null)
            {
                return;
            }

            EmbeddedImageValues eiv = new EmbeddedImageValues("embeddedimage");

            eiv.MIMEType  = "image/png";
            eiv.ImageData = imagedata;
            int cur = this.lbImages.Items.Add(eiv);

            lbImages.SelectedIndex = cur;

            this.tbEIName.Focus();
        }
        private void tbEIName_TextChanged(object sender, System.EventArgs e)
        {
            int cur = lbImages.SelectedIndex;

            if (cur < 0)
            {
                return;
            }

            EmbeddedImageValues eiv = lbImages.Items[cur] as EmbeddedImageValues;

            if (eiv == null)
            {
                return;
            }

            if (eiv.Name == tbEIName.Text)
            {
                return;
            }

            eiv.Name = tbEIName.Text;
            // text doesn't change in listbox; force change by removing and re-adding item
            lbImages.BeginUpdate();
            lbImages.Items.RemoveAt(cur);
            lbImages.Items.Insert(cur, eiv);
            lbImages.SelectedIndex = cur;
            lbImages.EndUpdate();
        }
        private void lbImages_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            int cur = lbImages.SelectedIndex;

            if (cur < 0)
            {
                return;
            }

            EmbeddedImageValues eiv = lbImages.Items[cur] as EmbeddedImageValues;

            if (eiv == null)
            {
                return;
            }

            tbEIName.Text           = eiv.Name;
            lbMIMEType.Text         = eiv.MIMEType;
            this.pictureImage.Image = GetImage(eiv.ImageData);
        }
        private void InitValues()
        {
            //
            // Obtain the existing DataSets info
            //
            XmlNode rNode  = _Draw.GetReportNode();
            XmlNode eiNode = _Draw.GetNamedChildNode(rNode, "EmbeddedImages");

            if (eiNode == null)
            {
                return;
            }
            foreach (XmlNode iNode in eiNode)
            {
                if (iNode.Name != "EmbeddedImage")
                {
                    continue;
                }
                XmlAttribute nAttr = iNode.Attributes["Name"];
                if (nAttr == null)                      // shouldn't really happen
                {
                    continue;
                }

                EmbeddedImageValues eiv = new EmbeddedImageValues(nAttr.Value);
                eiv.MIMEType  = _Draw.GetElementValue(iNode, "MIMEType", "image/png");
                eiv.ImageData = _Draw.GetElementValue(iNode, "ImageData", "");
                this.lbImages.Items.Add(eiv);
            }
            if (lbImages.Items.Count > 0)
            {
                lbImages.SelectedIndex = 0;
            }
            else
            {
                this.bOK.Enabled = false;
            }
        }
        private void bImport_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Bitmap Files (*.bmp)|*.bmp" +
                         "|JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif" +
                         "|GIF (*.gif)|*.gif" +
                         "|TIFF (*.tif;*.tiff)|*.tif;*.tiff" +
                         "|PNG (*.png)|*.png" +
                         "|All Picture Files|*.bmp;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif;*.tif;*.tiff;*.png" +
                         "|All files (*.*)|*.*";
            ofd.FilterIndex     = 6;
            ofd.CheckFileExists = true;
            ofd.Multiselect     = true;
            try
            {
                if (ofd.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                // need to create a new embedded image(s)
                int cur = 0;
                foreach (string filename in ofd.FileNames)
                {
                    Stream strm             = null;
                    System.Drawing.Image im = null;
                    string imagedata        = null;
                    try
                    {
                        strm      = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                        im        = System.Drawing.Image.FromStream(strm);
                        imagedata = this.GetBase64Image(im);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, ex.Message, "Image");
                    }
                    finally
                    {
                        if (strm != null)
                        {
                            strm.Close();
                        }
                        if (im != null)
                        {
                            im.Dispose();
                        }
                    }

                    if (imagedata != null)
                    {
                        FileInfo fi = new FileInfo(filename);

                        string fname;
                        int    offset = fi.Name.IndexOf('.');
                        if (offset >= 0)
                        {
                            fname = fi.Name.Substring(0, offset);
                        }
                        else
                        {
                            fname = fi.Name;
                        }

                        if (!ReportNames.IsNameValid(fname))
                        {
                            fname = "embeddedimage";
                        }
                        // Now check to see if we already have one with that name
                        int  index = 1;
                        bool bDup  = true;
                        while (bDup)
                        {
                            bDup = false;
                            foreach (EmbeddedImageValues ev in lbImages.Items)
                            {
                                if (fname == ev.Name)
                                {
                                    bDup = true;
                                    break;
                                }
                            }
                            if (bDup)
                            {                                                // we have a duplicate name; try adding an index number
                                fname  = Regex.Replace(fname, "[0-9]*", ""); // remove old numbers (side effect removes all numbers)
                                fname += index.ToString();
                                index++;
                            }
                        }

                        EmbeddedImageValues eiv = new EmbeddedImageValues(fname);
                        eiv.MIMEType  = "image/png";
                        eiv.ImageData = imagedata;
                        cur           = this.lbImages.Items.Add(eiv);
                    }
                }
                lbImages.SelectedIndex = cur;
            }
            finally
            {
                ofd.Dispose();
            }
            this.tbEIName.Focus();
        }
        private void InitValues()
        {
            //
            // Obtain the existing DataSets info
            //
            XmlNode rNode = _Draw.GetReportNode();
            XmlNode eiNode = _Draw.GetNamedChildNode(rNode, "EmbeddedImages");
            if (eiNode == null)
                return;
            foreach (XmlNode iNode in eiNode)
            {
                if (iNode.Name != "EmbeddedImage")
                    continue;
                XmlAttribute nAttr = iNode.Attributes["Name"];
                if (nAttr == null)	// shouldn't really happen
                    continue;

                EmbeddedImageValues eiv = new EmbeddedImageValues(nAttr.Value);
                eiv.MIMEType = _Draw.GetElementValue(iNode, "MIMEType", "image/png");
                eiv.ImageData = _Draw.GetElementValue(iNode, "ImageData", "");
                this.lbImages.Items.Add(eiv);
            }
            if (lbImages.Items.Count > 0)
                lbImages.SelectedIndex = 0;
            else
                this.bOK.Enabled = false;
        }
        private void bPaste_Click(object sender, System.EventArgs e)
        {
            // Make sure we have an image on the clipboard
            IDataObject iData = Clipboard.GetDataObject();
            if (iData == null || !iData.GetDataPresent(DataFormats.Bitmap))
            {
                MessageBox.Show(this, "Copy image into clipboard before attempting to paste.", "Image");
                return;
            }

            System.Drawing.Bitmap img = (System.Drawing.Bitmap) iData.GetData(DataFormats.Bitmap);

            // convert the image to the png format and create a base 64	string representation
            string imagedata=GetBase64Image(img);
            img.Dispose();

            if (imagedata == null)
                return;

            EmbeddedImageValues eiv = new EmbeddedImageValues("embeddedimage");
            eiv.MIMEType = "image/png";
            eiv.ImageData = imagedata;
            int cur = this.lbImages.Items.Add(eiv);

            lbImages.SelectedIndex = cur;

            this.tbEIName.Focus();
        }
        private void bImport_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Bitmap Files (*.bmp)|*.bmp" +
                "|JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif" +
                "|GIF (*.gif)|*.gif" +
                "|TIFF (*.tif;*.tiff)|*.tif;*.tiff" +
                "|PNG (*.png)|*.png" +
                "|All Picture Files|*.bmp;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif;*.tif;*.tiff;*.png" +
                "|All files (*.*)|*.*";
            ofd.FilterIndex = 6;
            ofd.CheckFileExists = true;
            ofd.Multiselect = true;
            try
            {
                if (ofd.ShowDialog(this) != DialogResult.OK)
                    return;

                // need to create a new embedded image(s)
                int cur = 0;
                foreach (string filename in ofd.FileNames)
                {
                    Stream strm = null;
                    System.Drawing.Image im = null;
                    string imagedata = null;
                    try
                    {
                        strm = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                        im = System.Drawing.Image.FromStream(strm);
                        imagedata = this.GetBase64Image(im);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, ex.Message, "Image");
                    }
                    finally
                    {
                        if (strm != null)
                            strm.Close();
                        if (im != null)
                            im.Dispose();
                    }

                    if (imagedata != null)
                    {
                        FileInfo fi = new FileInfo(filename);

                        string fname;
                        int offset = fi.Name.IndexOf('.');
                        if (offset >= 0)
                            fname = fi.Name.Substring(0, offset);
                        else
                            fname = fi.Name;

                        if (!ReportNames.IsNameValid(fname))
                            fname = "embeddedimage";
                        // Now check to see if we already have one with that name
                        int index = 1;
                        bool bDup = true;
                        while (bDup)
                        {
                            bDup = false;
                            foreach (EmbeddedImageValues ev in lbImages.Items)
                            {
                                if (fname == ev.Name)
                                {
                                    bDup = true;
                                    break;
                                }
                            }
                            if (bDup)
                            {	// we have a duplicate name; try adding an index number
                                fname = Regex.Replace(fname, "[0-9]*", "");		// remove old numbers (side effect removes all numbers)
                                fname += index.ToString();
                                index++;
                            }
                        }

                        EmbeddedImageValues eiv = new EmbeddedImageValues(fname);
                        eiv.MIMEType = "image/png";
                        eiv.ImageData = imagedata;
                        cur = this.lbImages.Items.Add(eiv);
                    }
                }
                lbImages.SelectedIndex = cur;
            }
            finally
            {
                ofd.Dispose();
            }
            this.tbEIName.Focus();
        }