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:
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)
{
OpenFileDialog openFileDialogE = new OpenFileDialog();
if (openFileDialogE.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
axAcroPDF1.src = openFileDialogE.FileName;
}
}
private void axAcroPDF1_MouseClick(object sender, MouseEventArgs e)
{
base.OnMouseClick(e);
textBox1.Text = e.X.ToString();
textBox2.Text = e.Y.ToString();
}
private void axAcroPDF1_MouseUp(object sender, MouseEventArgs e)
{
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:
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");
}
}
}