Hi Alex,
i would like to catch the click event on a WpfImageViewer with PDF Coordinates (to tell where the user has clicked on a pdf page). Is it possible? I would also like to show some rectangles on the pdf pages programmatically. How can i do that?
Best Regards
Yimei
Click event on WpfImageViewer
Moderator: Alex
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: Click event on WpfImageViewer
Hi Yimei,
Best regards, Alexander
Yes, this is possible. For doing the task you need:i would like to catch the click event on a WpfImageViewer with PDF Coordinates (to tell where the user has clicked on a pdf page). Is it possible?
- Subscribe to the WpfImageViewer.MouseDown event
- In handler of WpfImageViewer.MouseDown event
- Convert a point in mouse (screen) coordinates into a point in the viewer coordinates using the WpfImageViewer.PointFromScreen method
- Convert a point in viewer coordinates into a point in the image coordinates using the WpfImageViewer.PointToImage method:
http://www.vintasoft.com/docs/vsimaging ... Image.html - Convert a point in image coordinates into a point in the PDF page coordinates using the PdfPage.PointToUnit method:
http://www.vintasoft.com/docs/vsimaging ... oUnit.html
This is also possible. Please read how to do this here: http://www.vintasoft.com/docs/vsimaging ... fPage.htmlI would also like to show some rectangles on the pdf pages programmatically. How can i do that?
Best regards, Alexander
-
- Posts: 6
- Joined: Fri Oct 31, 2014 5:48 pm
Re: Click event on WpfImageViewer
Hi Alex,
thanks for the reply. I tried the MouseDown event. It works however only on the right mouse click. I would like to work with the left mouse click event. Is it possible?
Best Regards
Yimei
thanks for the reply. I tried the MouseDown event. It works however only on the right mouse click. I would like to work with the left mouse click event. Is it possible?
Best Regards
Yimei
-
- Posts: 6
- Joined: Fri Oct 31, 2014 5:48 pm
Re: Click event on WpfImageViewer
hi Alex,
could you please also tell me what ist the measurement of the Point if i get it from the PointToImage method?
Best Regards
Yimei Liao
could you please also tell me what ist the measurement of the Point if i get it from the PointToImage method?
Best Regards
Yimei Liao
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: Click event on WpfImageViewer
Hi Yimei,
Best regards, Alexander
There is no difference when you work with left or right mouse button. Could you share a snippet of your code?I tried the MouseDown event. It works however only on the right mouse click. I would like to work with the left mouse click event. Is it possible?
The PointToImage method (http://www.vintasoft.com/docs/vsimaging ... Image.html) returns point coordinate in pixels.could you please also tell me what ist the measurement of the Point if i get it from the PointToImage method?
Best regards, Alexander
-
- Posts: 6
- Joined: Fri Oct 31, 2014 5:48 pm
Re: Click event on WpfImageViewer
Hi Alex,
here is my code
Pdf_MouseDown is only triggered by the right mouse click.
Best Regards
Yimei Liao
here is my code
Code: Select all
imageViewer.MouseDown += new MouseButtonEventHandler(Pdf_MouseDown);
private void Pdf_MouseDown(object sender, MouseEventArgs e)
{
...
}
Best Regards
Yimei Liao
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: Click event on WpfImageViewer
Here is my code:
and it works correctly for left and right mouse buttons.
Please send working demo project which demonstrates the problem to support@vintasoft.com, we need reproduce your problem.
Best regards, Alexander
Code: Select all
...
this.imageViewer1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.imageViewer1_MouseClick);
this.imageViewer1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.imageViewer1_MouseDown);
...
private void imageViewer1_MouseDown(object sender, MouseEventArgs e)
{
MessageBox.Show("MouseDown " + e.Button.ToString());
}
private void imageViewer1_MouseClick(object sender, MouseEventArgs e)
{
MessageBox.Show("MouseClick " + e.Button.ToString());
}
Please send working demo project which demonstrates the problem to support@vintasoft.com, we need reproduce your problem.
Best regards, Alexander
-
- Posts: 6
- Joined: Fri Oct 31, 2014 5:48 pm
Re: Click event on WpfImageViewer
Hi Alex,
the MouseClick Event is not available. I would send you the example codes sortly.
Best regards
Yimei
the MouseClick Event is not available. I would send you the example codes sortly.
Best regards
Yimei
-
- Posts: 6
- Joined: Fri Oct 31, 2014 5:48 pm
Re: Click event on WpfImageViewer
Hi Alex,
i have yet another problem. I have some pdf documents, each containing only one page. I open the pdfs one after another, while showing a Rectangular on each of them. Problem is that sometimes the Rectangular shows and sometimes not. It looks like a race condition to me. My codes are like
Best regards
Yimei
i have yet another problem. I have some pdf documents, each containing only one page. I open the pdfs one after another, while showing a Rectangular on each of them. Problem is that sometimes the Rectangular shows and sometimes not. It looks like a race condition to me. My codes are like
Code: Select all
private void NextPdf_Click(){
openDocument(nextIndex);
showRectangular();
}
private void showRectangulars()
{
using (PdfGraphics graphics = PdfGraphics.FromPage(FocusedPage))
{
System.Drawing.PointF p = new System.Drawing.PointF((float)x, (float)y);
FocusedPage.PointToUnit(ref p);
System.Drawing.Color brushColor = System.Drawing.Color.FromArgb(0, 0, 0);
PdfBrush brush = new PdfBrush(brushColor, GraphicsStateBlendMode.Multiply);
PdfPen pen = new PdfPen(brushColor);
graphics.FillAndDrawRectangle(pen, brush, 100, 100, 200, 200);
}
imageViewer.Image.Reload(true);
}
private void OpenDocument(int index)
{
CloseDocument();
PdfDocumentController.AuthenticateRequest += new EventHandler<PdfDocumentOpenedEventArgs>(PdfDocumentController_AuthenticateRequest);
String filename = VM.getPdfName(index);
try
{
// try open in read-write mode
_documentStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite);
}
catch (IOException)
{
try
{
// try open in read mode
_documentStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
}
catch (IOException e)
{
Debug.Write(e);
return;
}
}
catch (Exception e)
{
Debug.Write(e);
return;
}
try
{
_document = PdfDocumentController.OpenDocument(_documentStream);
if (_document.IsEncrypted && _document.AuthorizationResult == AuthorizationResult.IncorrectPassword)
{
CloseDocument();
return;
}
}
catch (Exception e)
{
Debug.Write(e);
CloseDocument();
return;
}
_document.RenderingSettings.UseEmbeddedThumbnails = true;
try
{
imageViewer.Images.Add(_documentStream);
}
catch (Exception e)
{
Debug.Write(e);
CloseDocument();
return;
}
}
/// <summary>
/// get the password from the AppConfiguration
/// </summary>
void PdfDocumentController_AuthenticateRequest(object sender, PdfDocumentOpenedEventArgs e)
{
PdfDocument document = e.Document;
while (true)
{
AuthorizationResult authorization = document.Authenticate(AppConfiguration.PDF_DECRYPTION_KEY);
if (authorization == AuthorizationResult.IncorrectPassword)
{
Console.WriteLine("The password is incorrect.");
}
else
{
Console.WriteLine(authorization.ToString());
return;
}
}
}
Yimei
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: Click event on WpfImageViewer
Hi Yimei,
Best regards, Alexander
I think your code has logical mistake. Please send working demo project which demonstrates the problem to support@vintasoft.com, we need reproduce your problem.i have yet another problem. I have some pdf documents, each containing only one page. I open the pdfs one after another, while showing a Rectangular on each of them. Problem is that sometimes the Rectangular shows and sometimes not. It looks like a race condition to me. My codes are like
Best regards, Alexander