Класс RectangularTextAnnotationTransformer
В этом разделе
Представляет контроллер взаимодействия, который преобразует прямоугольные текстовые аннотации.
Объектная модель
Синтаксис
Пример
Вот пример, показывающий, как установить собственный шрифт, расположение и размер текстового поля текстовых аннотаций:
Public Class MainForm
Inherits System.Windows.Forms.Form
''' <summary>
''' Main annotation viewer.
''' </summary>
Private _viewer As Vintasoft.Imaging.Annotation.UI.AnnotationViewer
' ...
Public Sub New()
' ...
' subscribe to the FocusedAnnotationViewChanged event of viewer
' ...
AddHandler _viewer.FocusedAnnotationViewChanged, New System.EventHandler(Of Vintasoft.Imaging.Annotation.UI.AnnotationViewChangedEventArgs)(AddressOf _viewer_FocusedAnnotationViewChanged)
End Sub
''' <summary>
''' Handler of the FocusedAnnotationViewChanged event.
''' </summary>
Private Sub _viewer_FocusedAnnotationViewChanged(sender As Object, e As Vintasoft.Imaging.Annotation.UI.AnnotationViewChangedEventArgs)
' text transformer of old annotation
Dim textTransformer As Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.RectangularTextAnnotationTransformer = Nothing
If TypeOf e.OldValue Is Vintasoft.Imaging.Annotation.UI.TextAnnotationView Then
textTransformer = DirectCast(e.OldValue, Vintasoft.Imaging.Annotation.UI.TextAnnotationView).TextTransformer
ElseIf TypeOf e.OldValue Is Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView Then
textTransformer = DirectCast(e.OldValue, Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView).TextTransformer
End If
If textTransformer IsNot Nothing Then
' unsubscribe from the TextBoxUpdated event of viewer
RemoveHandler textTransformer.TextBoxTransformer.TextBoxUpdated, New System.EventHandler(Of Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs)(AddressOf textTransformer_TextBoxUpdated)
End If
' text transformer of new annotation
textTransformer = Nothing
If TypeOf e.NewValue Is Vintasoft.Imaging.Annotation.UI.TextAnnotationView Then
textTransformer = DirectCast(e.NewValue, Vintasoft.Imaging.Annotation.UI.TextAnnotationView).TextTransformer
ElseIf TypeOf e.NewValue Is Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView Then
textTransformer = DirectCast(e.NewValue, Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView).TextTransformer
End If
If textTransformer IsNot Nothing Then
' set new font of the text box
textTransformer.TextBox.Font = New System.Drawing.Font("Arial", 20, System.Drawing.FontStyle.Bold)
' set text box location and size calculation mode to manual
textTransformer.AutomaticallyCalculateTextBoxLocationAndSize = False
' subscribe to the TextBoxUpdated event of viewer
AddHandler textTransformer.TextBoxTransformer.TextBoxUpdated, New System.EventHandler(Of Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs)(AddressOf textTransformer_TextBoxUpdated)
End If
End Sub
''' <summary>
''' Handler of the TextBoxUpdated event.
''' Location and size of the text box are setting to such values that text box matches
''' the visible part of the text annotation.
''' </summary>
Private Sub textTransformer_TextBoxUpdated(sender As Object, e As Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs)
' get the text annotation
Dim textAnnotation As Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.IRectangularTextAnnotation = DirectCast(e.TextObject, Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.IRectangularTextAnnotation)
' get bounding box of the annotation in the coordinate system of the viewer
Dim annotationBoundingBox As System.Drawing.RectangleF = Vintasoft.Imaging.Utils.GraphicsUtils.TransformRect(textAnnotation.GetBoundingBox(), textAnnotation.GetPointTransform(_viewer, _viewer.Image))
' intersect with the visible area of the viewer
Dim newBounds As System.Drawing.Rectangle = System.Drawing.Rectangle.Intersect(System.Drawing.Rectangle.Round(annotationBoundingBox), _viewer.ClientRectangle)
' set new bounds
e.TextBox.Bounds = newBounds
End Sub
End Class
public class MainForm : System.Windows.Forms.Form
{
/// <summary>
/// Main annotation viewer.
/// </summary>
Vintasoft.Imaging.Annotation.UI.AnnotationViewer _viewer;
// ...
public MainForm()
{
// ...
// subscribe to the FocusedAnnotationViewChanged event of viewer
_viewer.FocusedAnnotationViewChanged +=
new System.EventHandler<Vintasoft.Imaging.Annotation.UI.AnnotationViewChangedEventArgs>(_viewer_FocusedAnnotationViewChanged);
// ...
}
/// <summary>
/// Handler of the FocusedAnnotationViewChanged event.
/// </summary>
void _viewer_FocusedAnnotationViewChanged(object sender, Vintasoft.Imaging.Annotation.UI.AnnotationViewChangedEventArgs e)
{
// text transformer of old annotation
Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.RectangularTextAnnotationTransformer textTransformer = null;
if (e.OldValue is Vintasoft.Imaging.Annotation.UI.TextAnnotationView)
{
textTransformer = ((Vintasoft.Imaging.Annotation.UI.TextAnnotationView)e.OldValue).TextTransformer;
}
else if (e.OldValue is Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView)
{
textTransformer = ((Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView)e.OldValue).TextTransformer;
}
if (textTransformer != null)
{
// unsubscribe from the TextBoxUpdated event of viewer
textTransformer.TextBoxTransformer.TextBoxUpdated -=
new System.EventHandler<Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs>(textTransformer_TextBoxUpdated);
}
// text transformer of new annotation
textTransformer = null;
if (e.NewValue is Vintasoft.Imaging.Annotation.UI.TextAnnotationView)
{
textTransformer = ((Vintasoft.Imaging.Annotation.UI.TextAnnotationView)e.NewValue).TextTransformer;
}
else if (e.NewValue is Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView)
{
textTransformer = ((Vintasoft.Imaging.Annotation.UI.FreeTextAnnotationView)e.NewValue).TextTransformer;
}
if (textTransformer != null)
{
// set new font of the text box
textTransformer.TextBox.Font = new System.Drawing.Font(
"Arial", 20, System.Drawing.FontStyle.Bold);
// set text box location and size calculation mode to manual
textTransformer.AutomaticallyCalculateTextBoxLocationAndSize = false;
// subscribe to the TextBoxUpdated event of viewer
textTransformer.TextBoxTransformer.TextBoxUpdated +=
new System.EventHandler<Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs>(textTransformer_TextBoxUpdated);
}
}
/// <summary>
/// Handler of the TextBoxUpdated event.
/// Location and size of the text box are setting to such values that text box matches
/// the visible part of the text annotation.
/// </summary>
void textTransformer_TextBoxUpdated(object sender, Vintasoft.Imaging.UI.VisualTools.UserInteraction.TextObjectTextBoxTransformerEventArgs e)
{
// get the text annotation
Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.IRectangularTextAnnotation textAnnotation =
(Vintasoft.Imaging.Annotation.UI.VisualTools.UserInteraction.IRectangularTextAnnotation)e.TextObject;
// get bounding box of the annotation in the coordinate system of the viewer
System.Drawing.RectangleF annotationBoundingBox = Vintasoft.Imaging.Utils.GraphicsUtils.TransformRect(
textAnnotation.GetBoundingBox(), textAnnotation.GetPointTransform(_viewer, _viewer.Image));
// intersect with the visible area of the viewer
System.Drawing.Rectangle newBounds = System.Drawing.Rectangle.Intersect(
System.Drawing.Rectangle.Round(annotationBoundingBox), _viewer.ClientRectangle);
// set new bounds
e.TextBox.Bounds = newBounds;
}
}
Иерархия наследования
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также