Rank: Advanced Member Groups: Member
Joined: 3/3/2008 Posts: 47 Points: 141
|
Hi,
May I know Is that possible to add background color to TextVObject? If yes, may i know how?
Please advice.
|
Rank: Advanced Member Groups: Administration
, Member
Joined: 3/10/2008 Posts: 23 Points: 69
|
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
Best regards, Tamila Ashrafova Aurigma Support Team
|