logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
Guest  
#1 Posted : Tuesday, August 16, 2016 2:52:40 AM(UTC)
Quote
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
Hello,

how can i enable multiselect for pages in the winform PDF viewer control?

f.e. the user should be able to select one or more pages to be deleted.

If the multiselect pages feature is not available is it possible to implement that?


Thanks in advance
Paul Rayman  
#2 Posted : Tuesday, August 16, 2016 5:03:46 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Hi,

You can easily implement this behaviour by self.
To do that you should create a derived class from PdfViewer and write the following code.

Code:

public class MyPdfViewer : PdfViewer
{
	//List containing the indices of the selected pages
	private List<int> _selectedPages = new List<int>();

	//Overrides the mouse down behaviour
	protected override void OnMouseDown(MouseEventArgs e)
	{
		try
		{
			//Determines the page to the mouse coordinates
			int pageIndex = this.PointInPage(e.Location);
			if (pageIndex < 0)
			{
				//If click outside the page, but in the viewer, then deselect all pages
				_selectedPages.Clear();
				Invalidate();
				return;
			}

			//if click inside selected page then do nothing
			if (_selectedPages.Contains(pageIndex))
				return;

			//Add a new page into list of selected pages and invalidate the PdfViewer
			_selectedPages.Add(pageIndex);
			Invalidate();
		}
		finally
		{
			//Execute the base behaviour
			base.OnMouseDown(e);
		}
	}

	//Overrides the drawing of current page highlight
	protected override void DrawCurrentPageHighlight(Graphics graphics, int pageIndex, Rectangle actualRect)
	{
		if (_selectedPages.Contains(pageIndex))
		{
			//if pageIndex inside a list of selected page, then highlight the border
			using (var pen = new Pen(this.CurrentPageHighlightColor, 8))
			{
				actualRect.Inflate(0, 0);
				var sm = graphics.SmoothingMode;
				graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
				graphics.DrawRectangle(pen, actualRect);
				graphics.SmoothingMode = sm;
			}
		}
	}
}

Edited by user Tuesday, August 16, 2016 5:07:05 PM(UTC)  | Reason: Not specified

Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.