This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
ChingYen  
#1 Posted : Sunday, June 8, 2008 9:41:40 AM(UTC)
ChingYen

Rank: Advanced Member

Groups: Guest
Joined: 3/3/2008(UTC)
Posts: 185

Thanks: 8 times
Hi,

May I know Is that possible to add background color to TextVObject? If yes, may i know how?

Please advice.

Tamila  
#2 Posted : Sunday, June 8, 2008 2:22:13 PM(UTC)
Tamila

Rank: Advanced Member

Groups: Guest
Joined: 3/9/2008(UTC)
Posts: 554

Was thanked: 1 time(s) in 1 post(s)
Hello Ching Yen,

Unfortunately, you cannot add background color in TextVObjectCreateDesigner class. But you can inherit your own class, which supports background color, from TextVObject class.

For example:

Code:

<System.Serializable()> Public Class TextWithBg
    Inherits TextVObject

    Dim _bgRect As RectangleVObject

    Public Sub New()
        _bgRect = New RectangleVObject(Me.TextArea)

        _bgRect.Brush = System.Drawing.Brushes.White
        _bgRect.Pen = Nothing
    End Sub

    Public Sub New(ByVal text As String, ByVal fontName As String, ByVal fontSize As Single, ByVal bounds As System.Drawing.RectangleF)
        MyBase.New(text, fontName, fontSize, bounds)

        _bgRect = New RectangleVObject(Me.TextArea)
        _bgRect.Pen = Nothing
    End Sub

    Public Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
        MyBase.New(info, context)

        _bgRect = New RectangleVObject(Me.TextArea)
        _bgRect.Brush = New System.Drawing.SolidBrush(Color.FromArgb(CType(info.GetValue("TextBackgroundColor", GetType(System.Int32)), Integer)))
    End Sub

    <System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.Demand, _
    SerializationFormatter:=True)> Public Overrides Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
        MyBase.GetObjectData(info, context)

        If Not TypeOf _bgRect.Brush Is System.Drawing.SolidBrush Then
            Throw New ApplicationException("Only solid brushes supported in TextWithBg class.")
        End If

        info.AddValue("TextBackgroundColor", CType(_bgRect.Brush, System.Drawing.SolidBrush).Color.ToArgb)
    End Sub

    Public Overrides Sub Draw(ByVal renderingRect As System.Drawing.Rectangle, ByVal g As System.Drawing.Graphics, ByVal coordinateMapper As ICoordinateMapper)
        Dim rectBounds As System.Drawing.RectangleF = _bgRect.GetVObjectBounds()
        Dim objBounds As System.Drawing.RectangleF = Me.TextArea
        If Not rectBounds.Equals(objBounds) Then
            Dim tmp As System.Drawing.Brush = _bgRect.Brush
            _bgRect = New RectangleVObject(Me.TextArea)
            _bgRect.Transform = Me.Transform
            _bgRect.Brush = tmp
        End If

        _bgRect.Transform = Me.Transform
        _bgRect.Draw(renderingRect, g, coordinateMapper)

        MyBase.Draw(renderingRect, g, coordinateMapper)
    End Sub

    Public Property BackgroundBrush() As System.Drawing.Brush
        Get
            Return _bgRect.Brush
        End Get
        Set(ByVal Value As System.Drawing.Brush)
            _bgRect.Brush = Value
        End Set
    End Property
End Class

Now you can change background color, text area size, text color ets.

This sample demonstrates how to use TextWithBg class:

Code:

Dim newText As New TextWithBg("Confidential", "Tahome", 25, New System.Drawing.RectangleF(100, 100, 150, 80))
            newText.Brush = Brushes.Gold
            newText.BackgroundBrush = Brushes.Yellow
            newText.Format.LineAlignment = StringAlignment.Center
            newText.Format.Alignment = StringAlignment.Center
            newText.Update()
            Me._multiLayerViewer.CurrentLayer.VObjects.Add(newText)

Best regards,

Tamila Ashrafova

Edited by user Sunday, June 8, 2008 8:34:40 PM(UTC)  | Reason: Not specified

Aurigma Support Team

UserPostedImage Follow Aurigma on Twitter!

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.