Page 1 of 2
Click event on WpfImageViewer
Posted: Fri Oct 31, 2014 7:28 pm
by waxwings
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
Re: Click event on WpfImageViewer
Posted: Sat Nov 01, 2014 9:34 am
by Alex
Hi Yimei,
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?
Yes, this is possible. For doing the task you need:
- Subscribe to the WpfImageViewer.MouseDown event
- In handler of WpfImageViewer.MouseDown event
I would also like to show some rectangles on the pdf pages programmatically. How can i do that?
This is also possible. Please read how to do this here:
http://www.vintasoft.com/docs/vsimaging ... fPage.html
Best regards, Alexander
Re: Click event on WpfImageViewer
Posted: Mon Nov 03, 2014 1:57 pm
by waxwings
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
Re: Click event on WpfImageViewer
Posted: Mon Nov 03, 2014 5:02 pm
by waxwings
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
Re: Click event on WpfImageViewer
Posted: Mon Nov 03, 2014 5:55 pm
by Alex
Hi Yimei,
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?
There is no difference when you work with left or right mouse button. Could you share a snippet of your code?
could you please also tell me what ist the measurement of the Point if i get it from the PointToImage method?
The PointToImage method (
http://www.vintasoft.com/docs/vsimaging ... Image.html) returns point coordinate in pixels.
Best regards, Alexander
Re: Click event on WpfImageViewer
Posted: Mon Nov 03, 2014 6:01 pm
by waxwings
Hi Alex,
here is my code
Code: Select all
imageViewer.MouseDown += new MouseButtonEventHandler(Pdf_MouseDown);
private void Pdf_MouseDown(object sender, MouseEventArgs e)
{
...
}
Pdf_MouseDown is only triggered by the right mouse click.
Best Regards
Yimei Liao
Re: Click event on WpfImageViewer
Posted: Mon Nov 03, 2014 6:18 pm
by Alex
Here is my code:
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());
}
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
Re: Click event on WpfImageViewer
Posted: Tue Nov 04, 2014 6:08 pm
by waxwings
Hi Alex,
the MouseClick Event is not available. I would send you the example codes sortly.
Best regards
Yimei
Re: Click event on WpfImageViewer
Posted: Tue Nov 04, 2014 6:21 pm
by waxwings
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
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;
}
}
}
Best regards
Yimei
Re: Click event on WpfImageViewer
Posted: Wed Nov 05, 2014 11:29 am
by Alex
Hi 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
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.
Best regards, Alexander