|
Imports System.IO
Imports System.Windows.Printing
Imports System.Windows.Media.Imaging
Public Class cFigure
Public tb As New TextBlock
Public type As MainPage.eFigure
Public iNumber As Integer
Public iChildren As Integer
Public bAux As Boolean
Public iPosition As Point
Public newImage As New Image()
''' <summary>
''' Set the ballon and the text and the mouse events
''' </summary>
''' <param name="sText">Text for the ballon</param>
''' <param name="pPosition">Coordinates (x,y) for the location of the ballon</param>
''' <param name="typeFigure">The Type of figure</param>
''' <param name="iActualBallon">The number of the ballon in the list of ballons</param>
''' <remarks></remarks>
Public Sub SetImage(ByVal sText As String, ByVal pPosition As Point, ByVal typeFigure As MainPage.eFigure, ByVal iActualBallon As Integer)
Dim sFigure As String = ""
'Set the text to the combobox
tb.Text = " " + sText
'Save the color of the text
tb.Foreground = New SolidColorBrush(Colors.Black)
'Set options to center the text and automatic wordwrap
tb.TextAlignment = System.Windows.TextAlignment.Center
tb.TextWrapping = TextWrapping.Wrap
type = typeFigure
iNumber = iActualBallon
'Set the image of the ballon
Select Case type
Case MainPage.eFigure.leftCloud
sFigure = "Images/left_cloud.png"
Case MainPage.eFigure.rightCloud
sFigure = "Images/right_cloud.png"
Case MainPage.eFigure.rightOval
sFigure = "Images/rght_oval.png"
Case MainPage.eFigure.leftOval
sFigure = "Images/left_oval.png"
Case MainPage.eFigure.rightBox
sFigure = "Images/right_box.png"
Case MainPage.eFigure.leftBox
sFigure = "Images/left_box.png"
Case MainPage.eFigure.Box
sFigure = "Images/box.png"
End Select
'The uri of the image of the ballon
Dim uriImage As New Uri(sFigure, UriKind.Relative)
'Get the stream of the image of the ballon
Dim oImageStream As Stream = Application.GetResourceStream(uriImage).Stream
'Create a new Image for the ballon
Dim oImage As New BitmapImage()
'Set the image of the ballon
oImage.SetSource(oImageStream)
'Set the size proportional to the text only for the ballons.
newImage.Width = tb.ActualWidth + 50
newImage.Height = tb.ActualHeight
'If the figure is different of the box add a space for center the text
If type <> MainPage.eFigure.Box Then
newImage.Height += 30
tb.SetValue(Canvas.TopProperty, pPosition.Y + 8)
Else
newImage.Height += 10
tb.SetValue(Canvas.TopProperty, pPosition.Y + 5)
End If
tb.SetValue(Canvas.LeftProperty, pPosition.X + 18)
newImage.SetValue(Canvas.LeftProperty, pPosition.X)
newImage.SetValue(Canvas.TopProperty, pPosition.Y)
iPosition.Y = tb.GetValue(Canvas.TopProperty)
iPosition.X = tb.GetValue(Canvas.TopProperty)
'Set the ballon with text
newImage.Source = oImage
newImage.Stretch = Stretch.Fill
'Set the events for the ballon
AddHandler newImage.MouseLeftButtonDown, AddressOf Image_Mouse_Button_Down
AddHandler newImage.MouseMove, AddressOf Image_Mouse_Button_Move
AddHandler newImage.MouseLeftButtonUp, AddressOf Image_Mouse_Button_Up
End Sub
''' <summary>
''' Set the position of the ballon
''' </summary>
''' <param name="pPosition">Coordinates (x,y) for the location of the ballon</param>
''' <remarks></remarks>
Public Sub SetPosition(ByVal pPosition As Point)
newImage.SetValue(Canvas.TopProperty, pPosition.Y)
newImage.SetValue(Canvas.LeftProperty, pPosition.X)
If type <> MainPage.eFigure.Box Then
tb.SetValue(Canvas.TopProperty, pPosition.Y + 8)
Else
tb.SetValue(Canvas.TopProperty, pPosition.Y + 5)
End If
tb.SetValue(Canvas.LeftProperty, pPosition.X + 18)
iPosition.Y = tb.GetValue(Canvas.TopProperty)
iPosition.X = tb.GetValue(Canvas.LeftProperty)
End Sub
Private Sub Image_Mouse_Button_Down(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
bAux = True
MainPage.iActualCloud = iNumber
End Sub
Private Sub Image_Mouse_Button_Move(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs)
End Sub
Private Sub Image_Mouse_Button_Up(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
bAux = False
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm a software developer. I like to develop web pages and desktop systems. I'm learning unity, xamarin, swift, android, security, UX