Get X and Y position of mouse click on GDViewer

Discussions about document viewing.
Post Reply
hardikv
Posts: 43
Joined: Thu Jan 27, 2011 11:46 am

Get X and Y position of mouse click on GDViewer

Post by hardikv » Fri Aug 03, 2012 10:11 am

Hi,

i have displayed one PDF file inside gdviewer control. gdviewer zmoo mode is selected by user it may be 100%, fixtowidth,fittiviewer etc.. it is not hardcode, any user can change zoom mode of GdViewer control.

i need to draw a line in displayed pdf of gdviewer. so i need exact starting position of mouse wit point and ending position of mouse with point to draw line.

Please provide me the detail and example of this problem.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Get X and Y position of mouse click on GDViewer

Post by Loïc » Fri Aug 03, 2012 10:18 am

Hello,

- Catch X & Y in the mouse event. This will be viewer coordinates.
- Then translate viewer coordinates to document coordinates by using the CoordViewerToDocument method.

Kind regards,

Loïc

hardikv
Posts: 43
Joined: Thu Jan 27, 2011 11:46 am

Re: Get X and Y position of mouse click on GDViewer

Post by hardikv » Fri Aug 03, 2012 10:34 am

Loïc wrote:Hello,

- Catch X & Y in the mouse event. This will be viewer coordinates.
- Then translate viewer coordinates to document coordinates by using the CoordViewerToDocument method.

Kind regards,

Loïc
Thanks Loic,

Can you please give me one sample code for this i have below code but it is not working.

Code: Select all

private void GdViewer1_MouseDown(object sender, MouseEventArgs e)
        {
                if (e.Button == MouseButtons.Left)
                {
                     isDrag = true;
                
                     int a = 0, b = 0;
                     GdViewer1.CoordDocumentToViewer(e.X, e.Y, ref a, ref b);
                     startPoint = new Point(a, b);
                  }
        }
in above example variable a and b return same result as e.X and e.y. so where is the problem.

Thanks

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Get X and Y position of mouse click on GDViewer

Post by Loïc » Fri Aug 03, 2012 11:00 am

I was talking about CoordViewerToDocument , not CoordDocumentToViewer.

Also, if you are dealing with PDF coordinates I will suggest you to convert them to inches:

Code: Select all

            int docXPix = 0, docYPix = 0;
            GdViewer1.CoordViewerToDocument(e.X, e.Y, ref docXPix, ref docYPix);

            double doXInches = docXPix / GdViewer1.HorizontalResolution ;
            double doYInches = docYPix / GdViewer1.VerticalResolution;
Hope this helps!

Loïc

hardikv
Posts: 43
Joined: Thu Jan 27, 2011 11:46 am

Re: Get X and Y position of mouse click on GDViewer

Post by hardikv » Fri Aug 03, 2012 12:00 pm

Loïc wrote:I was talking about CoordViewerToDocument , not CoordDocumentToViewer.

Also, if you are dealing with PDF coordinates I will suggest you to convert them to inches:

Code: Select all

            int docXPix = 0, docYPix = 0;
            GdViewer1.CoordViewerToDocument(e.X, e.Y, ref docXPix, ref docYPix);

            double doXInches = docXPix / GdViewer1.HorizontalResolution ;
            double doYInches = docYPix / GdViewer1.VerticalResolution;
Hope this helps!

Loïc

Thanks, it is working.

my main goal is to draw line on GDViewer using "AddLineAnnotation()" of GDPicture pdf class. but i have some problem in that. i have posted one thread on GDPicture forum. link is below. please help me to solve that problem also.


viewtopic.php?t=3844


Thanks

SamiKharma
Posts: 352
Joined: Tue Sep 27, 2011 11:47 am

Re: Get X and Y position of mouse click on GDViewer

Post by SamiKharma » Sun Aug 05, 2012 10:44 am

Hi,

It has been answered. Please do not refer to other tickets in the forum in your posts. Your threads will be answered in due time.

Best Regards,
Sami

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest