public void RemoveMetadataCoordinate(MetadataCoordinate coordinate)
 {
     currentPictureBox.Controls.Remove(coordinate.HoverPanel);
     currentPictureBox.Controls.Remove(coordinate.MetadataTag);
     metadataList.Remove(coordinate);
     RefreshMetadataList();
     currentPictureBox.Invalidate();
 }
        public void AddMetadataTag(MetadataCoordinate coordinate)
        {
            var tag = new MetadataTag();

            tag.MetadataName   = coordinate.MetadataName;
            tag.Tag            = coordinate;
            tag.OnNameChanged += ((sender, e) =>
            {
                ((sender as MetadataTag).Tag as MetadataCoordinate).MetadataName = (sender as MetadataTag).MetadataName;
                RefreshMetadataList();
            });

            tag.Location = new Point(coordinate.X, currentPictureBox.Height - coordinate.Y);
            tag.Hide();

            var panel = new TransparentPanel();

            panel.Location    = new Point(coordinate.X, currentPictureBox.Height - coordinate.Y - coordinate.Height);
            panel.Size        = new System.Drawing.Size(coordinate.Width, coordinate.Height);
            panel.Cursor      = System.Windows.Forms.Cursors.Hand;
            panel.MouseHover += ((s, ev) => { ((s as TransparentPanel).Tag as MetadataCoordinate).MetadataTag.Show(); });
            panel.MouseLeave += ((s, ev) =>
            {
                var metadataTag = ((s as TransparentPanel).Tag as MetadataCoordinate).MetadataTag;
                metadataTag.Hide();
                metadataTag.CancelEditing();
            });
            panel.Click += ((s, ev) => { ((s as TransparentPanel).Tag as MetadataCoordinate).MetadataTag.StartEditing(); });

            coordinate.HoverPanel = panel;

            MenuItem menuItem = new MenuItem("Eliminar", ((s, ev) =>
            {
                RemoveMetadataCoordinate(((s as MenuItem).Tag as MetadataCoordinate));
            }));

            menuItem.Tag = coordinate;


            panel.ContextMenu = new System.Windows.Forms.ContextMenu(new MenuItem[] { menuItem });
            panel.Tag         = coordinate;

            currentPictureBox.Controls.Add(tag);
            currentPictureBox.Controls.Add(panel);

            coordinate.MetadataTag = tag;

            mSelect.Size = new Size(0, 0);
            currentPictureBox.Invalidate();
            metadataList.Add(coordinate);
        }
        private void PictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            mDragging = false;
            mSelect   = drawingRectangle;

            if (mSelect.Width == 0 || mSelect.Height == 0)
            {
                return;
            }

            /*currentTest = GetTextInArea("C:\\Users\\mxi02001166a\\Documents\\Pegaso\\P_123456_autos_70_ZAQ349960101_ZAQ34996_000000_11122012_440_71704_019883_F_11122012_10315754.pdf",
             *  1, mSelect.X, pictureBox1.Size.Height - mSelect.Bottom, mSelect.Width, mSelect.Height); */

            string readText = GetTextInArea(currentPdfFilepath,
                                            currentPage, mSelect.X, (sender as PictureBox).Size.Height - mSelect.Bottom, mSelect.Width, mSelect.Height);

            if (string.IsNullOrEmpty(readText))
            {
                mSelect.Size = new Size(0, 0);
                currentPictureBox.Invalidate();
                return;
            }

            MetadataNameInputDialog metaNameInputDialog = new MetadataNameInputDialog();

            metaNameInputDialog.ReadText = readText;
            if (metaNameInputDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string metadataName     = metaNameInputDialog.MetadataName;
                string baseMetadataName = metaNameInputDialog.MetadataName;

                int index = 1;

                for (int i = 0; i < metadataList.Count; i++)
                {
                    if (metadataList[i].MetadataName == metadataName)
                    {
                        metadataName = baseMetadataName + " (" + index + ")";
                        index++;
                        i = -1;
                    }
                }

                var coordinate = new MetadataCoordinate()
                {
                    MetadataName = metadataName,
                    X            = mSelect.X,
                    Y            = currentPictureBox.Size.Height - mSelect.Bottom,
                    Width        = mSelect.Width,
                    Height       = mSelect.Height,
                    TestString   = readText,
                    Page         = currentPage
                };

                AddMetadataTag(coordinate);
                RefreshMetadataList();
            }
            else
            {
                mSelect.Size = new Size(0, 0);
                currentPictureBox.Invalidate();
            }
        }