|
|
Thank you very much Paul, it works perfectly !
|
|
|
Hmm... it works fine on my side. Make sure you are not missing this line.
|
|
|
Good morning Paul Rayman,
I've tried your solution and it's way better than the solution we were working on (the zoom doesn't focus on the left side of the screen anymore). But it's not very accurate. I mean that it doesn't zoom exactly on the cursor position. Do I have to put the cursor position in the ScrollToPoint function? ( pdfViewer1.ScrollToPoint(idx, "someting that represent the cursor position"); )
Thank you very much !
|
|
|
I am assuming that you are looking for a WPF solution and if so, try the following code example Code:
private void pdfViewer1_MouseWheel(object sender, MouseWheelEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
e.Handled = true;
int idx = pdfViewer1.CurrentIndex;
var mousePoint = e.GetPosition(this);
var leftTopPagePoint = pdfViewer1.ClientToPage(idx, new Point(0, 0));
var pagePoint = pdfViewer1.ClientToPage(idx, mousePoint);
if (e.Delta < 0 && pdfViewer1.Zoom > 0.4)
pdfViewer1.Zoom /= 1.3f;
else if (e.Delta > 0)
pdfViewer1.Zoom *= 1.3f;
pdfViewer1.SizeMode = SizeModes.Zoom;
var newPagePoint = pdfViewer1.ClientToPage(idx, mousePoint);
var offsetPoint = newPagePoint - pagePoint;
var scrollPoint = leftTopPagePoint - offsetPoint;
// Scroll the page point into view
pdfViewer1.ScrollToPoint(idx, scrollPoint);
}
}
|
|
|
Hello, I can see that this subject is a bit old (it a ex coworker who started it).
I'm now facing the same problem and there is noting clear about this on the web. The problem is that I'm not able to make a correct MousseWeel Zoom on my PdfViewer. It goes to the top left side of my window instead of focusing on the cursor. I glad that someone answered but it doesn't seem to work for me. But I see that you use the method PdfViewer.ScrollToPoint(). Is this the solution of my problem ?
Is there someone here who may have something for me to work with?
Thank you very much.
|
|
|
Not sure on the WPF implementation but I have been able to achieve this in Winforms. (Although its a bit sloppy). Code:
// Cache a copy of the current mouse position on page
var pagePoint = pdfViewer1.ClientToPage(_pdfViewer.CurrentIndex,
pdfViewer1.PointToClient(Cursor.Position));
// Set the zoom
pdfViewer1.Zoom = zoom;
pdfViewer1.SizeMode = SizeModes.Zoom;
// Copy page point back to new client relative position
var clientPoint = pdfViewer1.PageToClient(pdfViewer1.CurrentIndex, pagePoint);
var size = pdfViewer1.ClientSize;
// Set client point to half the viewer size (To place point in middle of page)
clientPoint.X -= size.Width / 2;
clientPoint.Y -= size.Height / 2;
// Set point back to page again
pagePoint = pdfViewer1.ClientToPage(pdfViewer1.CurrentIndex, clientPoint);
// Scroll the page point into view
pdfViewer1.ScrollToPoint(pdfViewer1.CurrentIndex, pagePoint);
It does jitter a bit, as the layout is recalculated during the zoom and again on applying the scroll to point afterwards. Seems like some changes may be required here: (Not sure?) https://github.com/Patagames/Pdf.WinForms/blob/master/PdfViewer.cs#L1439I also added this code to the top of the OnMouseWheel method: (As the main form uses ctrl key + mouse wheel to initiate scroll) https://github.com/Patagames/Pdf.WinForms/blob/master/PdfViewer.cs#L1657Code:
if ((ModifierKeys & Keys.Control) == Keys.Control)
{
base.OnMouseWheel(e);
return;
}
Would appreciate any insight into preventing the jittering, ie. delaying layout until the very end.
|
|
|
Hi guys ! I would like to zoom with MouseWheel (Delta > 0) or (Delta < 0) at Cursor Mouse position on PdfViewer. I used Pdfium.NET.SDK 3.7.4.2704 (latest version on February 2017) How to make this in C# ? Code:
<Grid Panel.ZIndex="1" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="3" Grid.RowSpan="2" x:Name="ScroolBar" >
<ScrollViewer x:Name="viewerScroll" Panel.ZIndex="3" CanContentScroll="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Wpf:PdfViewer x:Name="pdfViewer" MouseWheel="pdfViewer_MouseWheel" MouseMove="pdfViewer_MouseMove" Background="#AAA095" >
</Wpf:PdfViewer>
</ScrollViewer>
</Grid>
Code:
private void pdfViewer_MouseWheel(object sender, MouseWheelEventArgs e)
{
System.Windows.Point p = e.GetPosition(null);
//float newzoom = this.pdfViewer.Zoom;
//this.pdfViewer.PageToClient(this.pdfViewer.CurrentIndex, p);
if (e.Delta > 0)
{
calculZoomPlus();
}
else if(e.Delta < 0)
{
calculZoomMoins();
}
}
private void calculZoomPlus()
{
if (this.pdfViewer.Zoom < 0.125f)
{
this.pdfViewer.Zoom = 0.125f;
}
else if (this.pdfViewer.Zoom >= 0.125f && this.pdfViewer.Zoom < 4.00f)
{
this.pdfViewer.Zoom += 0.125f;
}
else if (this.pdfViewer.Zoom == 4.00f)
{
this.pdfViewer.Zoom = 4.00f;
}
}
private void calculZoomMoins()
{
if (this.pdfViewer.Zoom == 0.25f)
{
this.pdfViewer.Zoom = 0.125f;
}
else if (this.pdfViewer.Zoom <= 0.125f)
{
}
else if (this.pdfViewer.Zoom > 0.125f && this.pdfViewer.Zoom <= 4.00f)
{
this.pdfViewer.Zoom -= 0.125f;
}
}
Sorry for my bad english, I'm french. Thanks for your help.
|
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close