Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello Fellow Programmers,

I have made a C# Windows Forms Application in Visual Studio 2017 which opens up any PDF file. The form I use when I run the App is a box with a button (to open the pdf), two textboxes which give the X and Y coordinates of a mouse, and a box where the PDF opens. Unfortunately whenever I click in the PDF box nothing happens. How do I interact with the pdf and show the user where the mouse is during a click?

Code to open PDF:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e) //button to open PDF
        {
            OpenFileDialog openFileDialogE = new OpenFileDialog();

            if (openFileDialogE.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                axAcroPDF1.src = openFileDialogE.FileName;
            }
        }

        private void axAcroPDF1_MouseClick(object sender, MouseEventArgs e)
// supposed to record position on click        
{
            base.OnMouseClick(e);
            textBox1.Text = e.X.ToString();
            textBox2.Text = e.Y.ToString();
        }

        private void axAcroPDF1_MouseUp(object sender, MouseEventArgs e)
        // supposed to record position on release
        {
            textBox1.Text = e.X.ToString();
            textBox2.Text = e.Y.ToString();
            Console.WriteLine("mouse up");
        }
    }
}


What I have tried:

I adjusted an existing code which gives the user the coordinates of clicks wherever they click in a picture box. I modified it so that it would maybe work with a PDF box. I used it in my C# code. I also tested out the existing program by itself and it didn't work either.
I eventually want to output the on screen distance between when I start a click and when I let go.

Original code:

C#


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace testGraphiqueCSharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected void pictureBox1_MouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);
            textBox1.Text = e.X.ToString();
            textBox2.Text = e.Y.ToString();
        }

       private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            textBox1.Text = e.X.ToString();
            textBox2.Text = e.Y.ToString();
            Console.WriteLine("mouse up");
        }
    }
}
Posted
Updated 7-Sep-17 9:46am
v4
Comments
Richard MacCutchan 7-Sep-17 11:47am    
Where is the code to display the PDF file?
Member 13396929 7-Sep-17 12:00pm    
It's in the first window. It's under "private void button1_MouseClick()"
Richard MacCutchan 7-Sep-17 15:09pm    
Really? I cannot find any method with that signature. And unless you can explain exactly where the code is and what it is supposed to do, and what the problem is, it is unlikely that anyone can offer any suggestions.
Member 13396929 7-Sep-17 15:46pm    
I made a few small tweaks to my question, can you spot the code now?
Richard MacCutchan 8-Sep-17 1:06am    
No, I still do not see a method named button1_MouseClick(). Did you actually write this code? And the only place where I can see a reference to a PDF file is at axAcroPDF1.src = openFileDialogE.FileName;. Is that supposed to do the displaying?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900