VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.UI.VisualTools.GraphicObjects Namespace / TextGraphicObject Class
Members Example



In This Topic
    TextGraphicObject Class
    In This Topic
    Represents a static text which can be displayed in image viewer.
    Object Model
    TextGraphicObject ClassIInteractionController InterfaceImageViewerPointFTransform Class
    Syntax
    Example
    This example shows how to draw static text (filename, current zoom factor) over image in image viewer and draw a frame around image in image viewer:
    ''' <summary>
    ''' Visual tool that draws static text (filename, current zoom factor) over image in
    ''' image viewer and draws a frame around image in image viewer:
    ''' </summary>
    Public Class GraphicObjectToolExample
        Inherits Vintasoft.Imaging.UI.VisualTools.GraphicObjects.GraphicObjectTool
                
        #Region "Fields"
                
        ''' <summary>
        ''' The graphic object that draws a filename over the image in image viewer.
        ''' </summary>
        Private _fileNameGraphicObject As New Vintasoft.Imaging.UI.VisualTools.GraphicObjects.TextGraphicObject()
                
        ''' <summary>
        ''' The graphic object that draws image zoom factor over the image in image viewer.
        ''' </summary>
        Private _zoomGraphicObject As New Vintasoft.Imaging.UI.VisualTools.GraphicObjects.TextGraphicObject()
                
        ''' <summary>
        ''' The graphic object that draws a frame around image in image viewer.
        ''' </summary>
        Private _borderGraphicObject As New Vintasoft.Imaging.UI.VisualTools.GraphicObjects.RectangularGraphicObject()
                
        #End Region
                
                
                
        #Region "Constructors"
                
        ''' <summary>
        ''' Initializes a new instance of the <see cref="GraphicObjectToolExample"/> class.
        ''' </summary>
        Public Sub New()
            _fileNameGraphicObject.TextAnchor = Vintasoft.Imaging.UI.AnchorType.Top
            _fileNameGraphicObject.FontBrush = System.Drawing.Brushes.Salmon
            _fileNameGraphicObject.Font = New System.Drawing.Font("Arial", 24)
            GraphicObjectCollection.Add(_fileNameGraphicObject)
                
            _zoomGraphicObject.TextAnchor = Vintasoft.Imaging.UI.AnchorType.Bottom Or Vintasoft.Imaging.UI.AnchorType.Right
            _zoomGraphicObject.FontBrush = System.Drawing.Brushes.Lime
            _zoomGraphicObject.Font = New System.Drawing.Font("Arial", 20)
            GraphicObjectCollection.Add(_zoomGraphicObject)
                
            _borderGraphicObject.PointTransform = New Vintasoft.Imaging.UI.VisualTools.PixelsToImageViewerPointFTransform()
            _borderGraphicObject.Pen = New System.Drawing.Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.Lime), 10)
            GraphicObjectCollection.Add(_borderGraphicObject)
        End Sub
                
        #End Region
                
                
                
        #Region "Methods"
                
        ''' <summary>
        ''' Raises the <see cref="Vintasoft.Imaging.UI.VisualTools.VisualTool.Activated" /> event.
        ''' </summary>
        Protected Overrides Sub OnActivated(e As System.EventArgs)
            MyBase.OnActivated(e)
            AddHandler ImageViewer.ZoomChanged, New System.EventHandler(Of Vintasoft.Imaging.UI.ZoomChangedEventArgs)(AddressOf ImageViewer_ZoomChanged)
            AddHandler ImageViewer.ClientSizeChanged, New System.EventHandler(AddressOf ImageViewer_ClientSizeChanged)
            AddHandler ImageViewer.ImageLoaded, New System.EventHandler(Of Vintasoft.Imaging.ImageLoadedEventArgs)(AddressOf ImageViewer_ImageLoaded)
                
            UpdateGraphicObjects()
        End Sub
                
        ''' <summary>
        ''' Raises the <see cref="Vintasoft.Imaging.UI.VisualTools.VisualTool.Deactivated" /> event.
        ''' </summary>
        Protected Overrides Sub OnDeactivated(e As System.EventArgs)
            MyBase.OnDeactivated(e)
                
            RemoveHandler ImageViewer.ZoomChanged, AddressOf ImageViewer_ZoomChanged
            RemoveHandler ImageViewer.ClientSizeChanged, AddressOf ImageViewer_ClientSizeChanged
            RemoveHandler ImageViewer.ImageLoaded, AddressOf ImageViewer_ImageLoaded
        End Sub
                
        ''' <summary>
        ''' Updates the graphic objects.
        ''' </summary>
        Private Sub UpdateGraphicObjects()
            _fileNameGraphicObject.Rectangle = ImageViewer.ClientRectangle
            _zoomGraphicObject.Rectangle = ImageViewer.ClientRectangle
            _zoomGraphicObject.Text = String.Format("Zoom: {0}", ImageViewer.Zoom)
                
            Dim image As Vintasoft.Imaging.VintasoftImage = ImageViewer.Image
            If image Is Nothing Then
                _fileNameGraphicObject.Text = String.Empty
                _borderGraphicObject.Rectangle = System.Drawing.Rectangle.Empty
            Else
                Dim info As Vintasoft.Imaging.ImageSourceInfo = image.SourceInfo
                If String.IsNullOrEmpty(info.Filename) Then
                    _fileNameGraphicObject.Text = String.Empty
                Else
                    Dim text As String = System.IO.Path.GetFileName(info.Filename)
                    If info.PageCount > 1 Then
                        text += String.Format(" (Page {0}/{1})", info.PageIndex + 1, info.PageCount)
                    End If
                    _fileNameGraphicObject.Text = text
                End If
                
                _borderGraphicObject.Rectangle = New System.Drawing.RectangleF(0, 0, image.Width, image.Height)
            End If
        End Sub
                
        ''' <summary>
        ''' Handles the ClientSizeChanged event of the ImageViewer control.
        ''' </summary>
        Private Sub ImageViewer_ClientSizeChanged(sender As Object, e As System.EventArgs)
            UpdateGraphicObjects()
        End Sub
                
        ''' <summary>
        ''' Handles the ZoomChanged event of the ImageViewer control.
        ''' </summary>
        Private Sub ImageViewer_ZoomChanged(sender As Object, e As Vintasoft.Imaging.UI.ZoomChangedEventArgs)
            UpdateGraphicObjects()
        End Sub
                
        ''' <summary>
        ''' Handles the ImageLoaded event of the ImageViewer control.
        ''' </summary>
        Private Sub ImageViewer_ImageLoaded(sender As Object, e As Vintasoft.Imaging.ImageLoadedEventArgs)
            UpdateGraphicObjects()
        End Sub
                
        #End Region
                
    End Class
    /// <summary>
    /// Visual tool that draws static text (filename, current zoom factor) over image in
    /// image viewer and draws a frame around image in image viewer:
    /// </summary>
    public class GraphicObjectToolExample : 
        Vintasoft.Imaging.UI.VisualTools.GraphicObjects.GraphicObjectTool
    {
                
        #region Fields
                
        /// <summary>
        /// The graphic object that draws a filename over the image in image viewer.
        /// </summary>
        Vintasoft.Imaging.UI.VisualTools.GraphicObjects.TextGraphicObject _fileNameGraphicObject = 
            new Vintasoft.Imaging.UI.VisualTools.GraphicObjects.TextGraphicObject();
                
        /// <summary>
        /// The graphic object that draws image zoom factor over the image in image viewer.
        /// </summary>
        Vintasoft.Imaging.UI.VisualTools.GraphicObjects.TextGraphicObject _zoomGraphicObject = 
            new Vintasoft.Imaging.UI.VisualTools.GraphicObjects.TextGraphicObject();
                
        /// <summary>
        /// The graphic object that draws a frame around image in image viewer.
        /// </summary>
        Vintasoft.Imaging.UI.VisualTools.GraphicObjects.RectangularGraphicObject _borderGraphicObject = 
            new Vintasoft.Imaging.UI.VisualTools.GraphicObjects.RectangularGraphicObject();
                
        #endregion
                
                
                
        #region Constructors
                
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicObjectToolExample"/> class.
        /// </summary>
        public GraphicObjectToolExample()
        {
            _fileNameGraphicObject.TextAnchor = Vintasoft.Imaging.UI.AnchorType.Top;
            _fileNameGraphicObject.FontBrush = System.Drawing.Brushes.Salmon;
            _fileNameGraphicObject.Font = new System.Drawing.Font("Arial", 24);
            GraphicObjectCollection.Add(_fileNameGraphicObject);
                
            _zoomGraphicObject.TextAnchor = 
                Vintasoft.Imaging.UI.AnchorType.Bottom | Vintasoft.Imaging.UI.AnchorType.Right;
            _zoomGraphicObject.FontBrush = System.Drawing.Brushes.Lime;
            _zoomGraphicObject.Font = new System.Drawing.Font("Arial", 20);
            GraphicObjectCollection.Add(_zoomGraphicObject);
                
            _borderGraphicObject.PointTransform = 
                new Vintasoft.Imaging.UI.VisualTools.PixelsToImageViewerPointFTransform();
            _borderGraphicObject.Pen = new System.Drawing.Pen(
                System.Drawing.Color.FromArgb(128, System.Drawing.Color.Lime), 10);
            GraphicObjectCollection.Add(_borderGraphicObject);
        }
                
        #endregion
                
                
                
        #region Methods
                
        /// <summary>
        /// Raises the <see cref="Vintasoft.Imaging.UI.VisualTools.VisualTool.Activated" /> event.
        /// </summary>
        protected override void OnActivated(System.EventArgs e)
        {
            base.OnActivated(e);
            ImageViewer.ZoomChanged += 
                new System.EventHandler<Vintasoft.Imaging.UI.ZoomChangedEventArgs>(ImageViewer_ZoomChanged);
            ImageViewer.ClientSizeChanged += new System.EventHandler(ImageViewer_ClientSizeChanged);
            ImageViewer.ImageLoaded += 
                new System.EventHandler<Vintasoft.Imaging.ImageLoadedEventArgs>(ImageViewer_ImageLoaded);
                
            UpdateGraphicObjects();
        }
                
        /// <summary>
        /// Raises the <see cref="Vintasoft.Imaging.UI.VisualTools.VisualTool.Deactivated" /> event.
        /// </summary>
        protected override void OnDeactivated(System.EventArgs e)
        {
            base.OnDeactivated(e);
                
            ImageViewer.ZoomChanged -= ImageViewer_ZoomChanged;
            ImageViewer.ClientSizeChanged -= ImageViewer_ClientSizeChanged;
            ImageViewer.ImageLoaded -= ImageViewer_ImageLoaded;
        }
                
        /// <summary>
        /// Updates the graphic objects.
        /// </summary>
        void UpdateGraphicObjects()
        {
            _fileNameGraphicObject.Rectangle = ImageViewer.ClientRectangle;
            _zoomGraphicObject.Rectangle = ImageViewer.ClientRectangle;
            _zoomGraphicObject.Text = string.Format("Zoom: {0}", ImageViewer.Zoom);
                
            Vintasoft.Imaging.VintasoftImage image = ImageViewer.Image;
            if (image == null)
            {
                _fileNameGraphicObject.Text = string.Empty;
                _borderGraphicObject.Rectangle = System.Drawing.Rectangle.Empty;
            }
            else
            {
                Vintasoft.Imaging.ImageSourceInfo info = image.SourceInfo;
                if (string.IsNullOrEmpty(info.Filename))
                    _fileNameGraphicObject.Text = string.Empty;
                else
                {
                    string text = System.IO.Path.GetFileName(info.Filename);
                    if (info.PageCount > 1)
                        text += string.Format(" (Page {0}/{1})", info.PageIndex + 1, info.PageCount);
                    _fileNameGraphicObject.Text = text;
                }
                
                _borderGraphicObject.Rectangle = new System.Drawing.RectangleF(0, 0, image.Width, image.Height);
            }
        }
                
        /// <summary>
        /// Handles the ClientSizeChanged event of the ImageViewer control.
        /// </summary>
        void ImageViewer_ClientSizeChanged(object sender, System.EventArgs e)
        {
            UpdateGraphicObjects();
        }
                
        /// <summary>
        /// Handles the ZoomChanged event of the ImageViewer control.
        /// </summary>
        void ImageViewer_ZoomChanged(object sender, Vintasoft.Imaging.UI.ZoomChangedEventArgs e)
        {
            UpdateGraphicObjects();
        }
                
        /// <summary>
        /// Handles the ImageLoaded event of the ImageViewer control.
        /// </summary>
        void ImageViewer_ImageLoaded(object sender, Vintasoft.Imaging.ImageLoadedEventArgs e)
        {
            UpdateGraphicObjects();
        }
                
        #endregion
                
    }
    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.UI.VisualTools.GraphicObjects.GraphicObject
          Vintasoft.Imaging.UI.VisualTools.GraphicObjects.RectangularGraphicObject
             Vintasoft.Imaging.UI.VisualTools.GraphicObjects.TextGraphicObject

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also