Drag and Drop location zoomed
Posted: Mon Mar 24, 2014 8:29 pm
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?
Thanks,
Dave
Thanks,
Dave
Code: Select all
private void annotationViewer1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.StringFormat))
{
var str = (string)e.Data.GetData(DataFormats.StringFormat);
if (str.Length > 0)
{
float zoomFactor = ((annotationViewer1.ZoomExtended -100)/100);
Point clientLocation = annotationViewer1.PointToClient(new Point(e.X, e.Y));
PointF imageLocation = annotationViewer1.PointToImageF(new PointF(e.X, e.Y));
PointF test1 = annotationViewer1.PointToImageF(new PointF(clientLocation.X, clientLocation.Y));
float clientx = clientLocation.X * zoomFactor;
float clienty = clientLocation.Y;
StickyNoteAnnotationData stickyNote = new StickyNoteAnnotationData();
stickyNote.FillBrush = new AnnotationSolidBrush(Color.Yellow);
stickyNote.CollapsedTextData.Text = str;
stickyNote.CollapsedTextData.TextPadding = new PaddingF(0f);
stickyNote.CollapsedTextData.Font = new AnnotationFont("Tahoma", 12);
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;
stickyNote.Location = test1;
annotationViewer1.AddAndBuildAnnotation(stickyNote);
}
}
}