VintaSoft Imaging .NET SDK and Plug-ins Discussions

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Board index < VintaSoft Imaging < VintaSoft Imaging .NET SDK and Plug-ins Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

Click event on WpfImageViewer



Click event on WpfImageViewer

Post 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

Post 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: https://www.vintasoft.com/docs/vsimaging ... fPage.html


Best regards, Alexander


Re: Click event on WpfImageViewer

Post 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

Post 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

Post 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 (https://www.vintasoft.com/docs/vsimaging ... Image.html) returns point coordinate in pixels.

Best regards, Alexander


Re: Click event on WpfImageViewer

Post by waxwings »

Hi Alex,

here is my code
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

Post by Alex »

Here is my code:
...
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

Post 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

Post 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
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

Post 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


Page 1 from 2: 1 2