I can't seem to figure out the combination on how to drag and drop a note to the viewer in the correct location. I've tried the following but the annotation is always quite a bit off. Does anyone know how to translate the X and Y coordinates for the drop event to the location of the annotation?
// Get the cordinates of the point on screen to client
Point clientLocation = annotationViewer1.PointToClient(new Point(e.X, e.Y));
// Get the point of the image in the viewer
PointF imageLocation = annotationViewer1.PointToImageF(new PointF(clientLocation.X, clientLocation.Y));
// Convert the resolution to the image
float multX = annotationViewer1.Image.Resolution.Horizontal/96;
float multY = annotationViewer1.Image.Resolution.Vertical/96;
float x = imageLocation.X/multX;
float y = imageLocation.Y/multY;
var stickyNote = new StickyNoteAnnotationData();
stickyNote.FillBrush = new AnnotationSolidBrush(Color.Yellow);
stickyNote.CollapsedTextData.Text = str;
stickyNote.CollapsedTextData.TextPadding = new PaddingF(0f);
stickyNote.CollapsedTextData.Font = new AnnotationFont(defaultFont.Name, defaultFont.Size);
stickyNote.CollapsedTextData.AutoSize = true;
stickyNote.CanMirror = false;
stickyNote.CanResize = false;
stickyNote.CollapsedTextData.Font.Underline = true;
stickyNote.Outline.Color = Color.Red;
stickyNote.CollapsedTextData.TextAlign = ContentAlignment.MiddleCenter;
// Adjust for text width
Size textSize = TextRenderer.MeasureText(str, defaultFont);
// DPI Adjust
float w = (float)Math.Ceiling((float)textSize.Width / 96f * 100f);
stickyNote.Location = new PointF(x + (w / 2) - 20, y);
annotationViewer1.AddAndBuildAnnotation(stickyNote);
Your code is correct. First, you converted screen coordinates to the viewer coordinates. Next, you converted viewer coordinates to the image coordinates. Finally, you converted image coordinates to the annotation coordinates in DIP.