Invalidate Background

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
mbz
User
Posts: 39
Joined: Wed Jul 13, 2016 2:50 pm

Invalidate Background

Post by mbz »

Hey guys.
For my project, I need to invalidate not only the pages but also the gray "background" of the AxPXV_Control. Is there any way to get this done? I can't find any solution.

Regards,
mbz
mbz
User
Posts: 39
Joined: Wed Jul 13, 2016 2:50 pm

Re: Invalidate Background

Post by mbz »

mbz wrote:Hey guys.
For my project, I need to invalidate not only the pages but also the gray "background" of the AxPXV_Control. Is there any way to get this done? I can't find any solution.

Regards,
mbz
Ok. Sorry for that post. AxPXV_Control.Refresh is working fine now. The problem has been on my site. You can close this thread, if you want :)

I apologize!

Regards,
mbz
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Invalidate Background

Post by Sasha - Tracker Dev Team »

Hello mbz,

Just wanted to reply with that answer. Glad you solved your problem. =)

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mbz
User
Posts: 39
Joined: Wed Jul 13, 2016 2:50 pm

Re: Invalidate Background

Post by mbz »

Sasha - Tracker Dev Team wrote:Hello mbz,

Just wanted to reply with that answer. Glad you solved your problem. =)

Cheers,
Alex

Thank you for your effort! =)
Even though there seems to be a problem. If I do the AxPXV_Control.Refresh() the pdf pages are drawn pretty buggy:

Image

Maybe you know why?
If I redraw the pages directly after the refresh of the control, it lags.

Regards,
mbz
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Invalidate Background

Post by Sasha - Tracker Dev Team »

Hello mbz,

It would be better to update the IPXV_PagesView itself by using Redraw, or even better RedrawRect methods. That would update only the pages view, not an entire Control.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mbz
User
Posts: 39
Joined: Wed Jul 13, 2016 2:50 pm

Re: Invalidate Background

Post by mbz »

Hi Alex!
Thanks for your reply!

The Problem is, I need to redraw the entire control because I'm drawing next to the pages into the gray area. Unfortunately updating the IPXV_PagesView does not include that area.

Regards,
mbz
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Invalidate Background

Post by Sasha - Tracker Dev Team »

Hello mbz,

Can you please provide a piece of code or even better a working sample project that we can try, so we can assist you further?

Cheers,
Alex.
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mbz
User
Posts: 39
Joined: Wed Jul 13, 2016 2:50 pm

Re: Invalidate Background

Post by mbz »

Hi Alex!
Well, I need to provide the possibility to comment a point on the pdf without annotate the pdf itself, but save the "comment" in a database. To make that possible - and give the user the illusion that the comment is on the pdf - I'm drawing the comment (at the moment it's only the line) on a transparent panel.

This is the code:

Code: Select all

public sealed class DrawPanel : Panel, IEventHandler
{
	private List<Comment> _comments;
	public DrawPanel(AxPXV_Control pdfControl, int width, int height)
	{
		_pdfControl = pdfControl;
		_pagesLayoutManager = _pdfControl.Doc.ActiveView.PagesView.Layout;
		_comments = new List<Comment>();
		Width = width;
		Height = height;
	}

	private readonly IPXV_PagesLayoutManager _pagesLayoutManager;
	private AxPXV_Control _pdfControl;

	protected override void OnPaint(PaintEventArgs e)
	{
		base.OnPaint(e);
		DrawLine(_comments.ToArray());
	}

	protected override CreateParams CreateParams
	{
		get
		{
			var cp = base.CreateParams;
			cp.ExStyle |= 0x00000020; //WM_EX_TRANSPARENT
			return cp;
		}
	}

	public void DrawLine(params Comment[] commentToDraw)
	{
		using (var graphics = CreateGraphics())
		{
			if (commentToDraw.Length.Equals(0)) return;

			foreach (var comment in commentToDraw)
			{
				if (comment.Page < 0) return;

				if (!_comments.Contains(comment))
					_comments.Add(comment);

				var startDrawingPoint = GetDevicePoint(comment.Page, comment.StartingPointX, comment.StartingPointY);

				var endDrawingPoint = new Point(Right + 120, startDrawingPoint.Y);
				graphics.DrawLine(Pens.Red, startDrawingPoint, endDrawingPoint);
			}
		}
	}

	private const int HTTRANSPARENT = -1;
	protected override void WndProc(ref Message m)
	{
		switch (m.Msg)
		{
			case 0x84:
				m.Result = (IntPtr)HTTRANSPARENT;
				break;
			case 0x0014:
				m.Result = (IntPtr)1;
				break;
			default:
				base.WndProc(ref m);
				break;
		}
	}

	private Point GetDevicePoint(int page, double pointX, double pointY)
	{
		var tagPointOnDevice = _pagesLayoutManager.PagePointToDevicePoint(
					(uint)page,
					new PXC_Point { x = pointX, y = pointY },
					true);

		return new Point(tagPointOnDevice.x, tagPointOnDevice.y);
	}

	public void OnEvent(int nEventID, IEvent pEvent, object pFrom)
	{
		var rect = _pdfControl.ClientRectangle;
		var tagRect = new tagRECT
		{
			bottom = rect.Bottom,
			top = rect.Top,
			right = rect.Right,
			left = rect.Left
		};

		_pdfControl.Refresh();
		Invalidate();
		pEvent.Handled = false;
	}
}
Everything works fine except the redraw of the control when the pdf is scrolled.

Hope that can help you to help me :lol:

Regards,
mbz
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Invalidate Background

Post by Sasha - Tracker Dev Team »

Hello mbz,

I've drawn a small rectangle on the gray part of the Pages View, by using the IPXV_PagesViewDrawCallback. Here's the sample that I wrote some time ago - just change the rectangle coordinates to what you need:
https://gist.github.com/Polaringu/bee53 ... 7741e8bf79
And to refresh the gray part, I used the e.pagesView.layoutChanged event of the Control and launched a piece of code there:

Code: Select all

pdfCtl.Doc.ActiveView.PagesView.Redraw();
And everything updated as it needs to.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ