Create Annotation on Right Click of C# Window Application

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

Post Reply
dixit.patel1
Posts: 14
Joined: Fri Feb 02, 2024 1:20 pm

Create Annotation on Right Click of C# Window Application

Post by dixit.patel1 »

Hello,

I have created annotation on MouseClick Event but the annotation in not proper placed in location where mouse is right clicked,
it is not working in all tiff files, it shows wrong position and not showing annotation on document viwer.

I am using below Code Snippet.

Code: Select all

private void annotationViewer1_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        AnnotationView annotationView = null;
        AnnotationData data = null;
        data = new RectangleAnnotationData();
        data.FillBrush = new AnnotationSolidBrush(Color.Green);

        var xPlace = AnnotationViewer.Images[annotationViewer1.FocusedIndex].Resolution.Horizontal;
        var yPlace = AnnotationViewer.Images[annotationViewer1.FocusedIndex].Resolution.Vertical;

        var xPoint = 96 / xPlace;
        var yPoint = 96 / yPlace;

        var xPosition = Convert.ToDecimal(Convert.ToInt32(e.X) * xPoint);
        var yPosition = Convert.ToDecimal(Convert.ToInt32(e.Y) * yPoint);
        var wSize = Convert.ToDecimal(Convert.ToInt32(10) * xPoint);
        var hSize = Convert.ToDecimal(Convert.ToInt32(10) * yPoint);

        var xLocation = Convert.ToDecimal(xPosition + wSize / 2);
        var yLocation = Convert.ToDecimal(yPosition + hSize / 2);

        data.Location = new Point(Convert.ToInt32(xLocation), Convert.ToInt32(yLocation));
        data.Size = new Size(Convert.ToInt32(wSize), Convert.ToInt32(hSize));

        if (data != null)
        {
            // start the annotation building
            AnnotationViewer.AddAndBuildAnnotation(data);
        }
    }
}
Alex
Site Admin
Posts: 2319
Joined: Thu Jul 10, 2008 2:21 pm

Re: Create Annotation on Right Click of C# Window Application

Post by Alex »

Hello,

Your code has logical mistake.

If you want to convert screen point into viewer point, please use the ImageViewer.PointToClient method.

If you want to convert viewer point into annotation point, please use the ImageViewer.PointFromControlToDip method.

Best regards, Alexander
Post Reply