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);
}
}
}