Click here to Skip to main content
15,886,095 members
Articles / Web Development

Silverlight web comic

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
7 Feb 2012CPOL3 min read 18.3K   305   5  
Its a silverlight page to create a simple comic with photos and text-ballons
  • comic.zip
    • comic
      • comic.sln
      • comic.suo
      • comic.Web
      • comic
        • App.xaml
        • App.xaml.vb
        • Bin
          • Debug
            • AppManifest.xaml
            • ar
              • System.ComponentModel.DataAnnotations.resources.dll
            • bg
              • System.ComponentModel.DataAnnotations.resources.dll
            • ca
              • System.ComponentModel.DataAnnotations.resources.dll
            • comic.dll
            • comic.pdb
            • comic.xap
            • comic.xml
            • comicTestPage.html
            • cs
              • System.ComponentModel.DataAnnotations.resources.dll
            • da
              • System.ComponentModel.DataAnnotations.resources.dll
            • de
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
            • el
              • System.ComponentModel.DataAnnotations.resources.dll
            • es
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
            • et
              • System.ComponentModel.DataAnnotations.resources.dll
            • eu
              • System.ComponentModel.DataAnnotations.resources.dll
            • fi
              • System.ComponentModel.DataAnnotations.resources.dll
            • fr
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
            • he
              • System.ComponentModel.DataAnnotations.resources.dll
            • hr
              • System.ComponentModel.DataAnnotations.resources.dll
            • hu
              • System.ComponentModel.DataAnnotations.resources.dll
            • id
              • System.ComponentModel.DataAnnotations.resources.dll
            • Images
              • nube_derecha.png
              • nube_derecha1.png
              • nube_izquierda.png
              • nube_izquierda1.png
              • nuebe1.jpg
              • nuebe1.jpg.png
              • ovalo_derecha1.png
              • ovalo_izquierda1.png
              • rectangulo_derecha1.png
              • rectangulo_izquierdo1.png
              • rectangulo1.png
            • it
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
            • ja
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
            • ko
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
            • lt
              • System.ComponentModel.DataAnnotations.resources.dll
            • lv
              • System.ComponentModel.DataAnnotations.resources.dll
            • ms
              • System.ComponentModel.DataAnnotations.resources.dll
            • nl
              • System.ComponentModel.DataAnnotations.resources.dll
            • no
              • System.ComponentModel.DataAnnotations.resources.dll
            • pl
              • System.ComponentModel.DataAnnotations.resources.dll
            • pt
              • System.ComponentModel.DataAnnotations.resources.dll
            • pt-BR
              • System.ComponentModel.DataAnnotations.resources.dll
            • ro
              • System.ComponentModel.DataAnnotations.resources.dll
            • ru
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
            • sk
              • System.ComponentModel.DataAnnotations.resources.dll
            • sl
              • System.ComponentModel.DataAnnotations.resources.dll
            • sr-Cyrl-CS
              • System.ComponentModel.DataAnnotations.resources.dll
            • sr-Latn-CS
              • System.ComponentModel.DataAnnotations.resources.dll
            • sv
              • System.ComponentModel.DataAnnotations.resources.dll
            • System.ComponentModel.DataAnnotations.dll
            • System.ComponentModel.DataAnnotations.xml
            • System.ServiceModel.DomainServices.Client.dll
            • System.ServiceModel.DomainServices.Client.Web.dll
            • System.ServiceModel.DomainServices.Client.Web.xml
            • System.ServiceModel.DomainServices.Client.xml
            • System.ServiceModel.Web.Extensions.dll
            • System.ServiceModel.Web.Extensions.xml
            • th
              • System.ComponentModel.DataAnnotations.resources.dll
            • tr
              • System.ComponentModel.DataAnnotations.resources.dll
            • uk
              • System.ComponentModel.DataAnnotations.resources.dll
            • vi
              • System.ComponentModel.DataAnnotations.resources.dll
            • zh-Hans
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
            • zh-Hant
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
        • clases
        • comic.sln
        • comic.suo
        • comic.vbproj
        • comic.vbproj.user
        • comic.Web
        • comic
          • App.xaml
          • App.xaml.vb
          • Bin
            • Debug
              • AppManifest.xaml
              • ar
                • System.ComponentModel.DataAnnotations.resources.dll
              • bg
                • System.ComponentModel.DataAnnotations.resources.dll
              • ca
                • System.ComponentModel.DataAnnotations.resources.dll
              • comic.dll
              • comic.pdb
              • comic.xap
              • comic.xml
              • comicTestPage.html
              • cs
                • System.ComponentModel.DataAnnotations.resources.dll
              • da
                • System.ComponentModel.DataAnnotations.resources.dll
              • de
                • System.ComponentModel.DataAnnotations.resources.dll
                • System.ServiceModel.DomainServices.Client.resources.dll
                • System.ServiceModel.DomainServices.Client.Web.resources.dll
                • System.ServiceModel.Web.Extensions.resources.dll
              • el
                • System.ComponentModel.DataAnnotations.resources.dll
              • es
                • System.ComponentModel.DataAnnotations.resources.dll
                • System.ServiceModel.DomainServices.Client.resources.dll
                • System.ServiceModel.DomainServices.Client.Web.resources.dll
                • System.ServiceModel.Web.Extensions.resources.dll
              • et
                • System.ComponentModel.DataAnnotations.resources.dll
              • eu
                • System.ComponentModel.DataAnnotations.resources.dll
              • fi
                • System.ComponentModel.DataAnnotations.resources.dll
              • fr
                • System.ComponentModel.DataAnnotations.resources.dll
                • System.ServiceModel.DomainServices.Client.resources.dll
                • System.ServiceModel.DomainServices.Client.Web.resources.dll
                • System.ServiceModel.Web.Extensions.resources.dll
              • he
                • System.ComponentModel.DataAnnotations.resources.dll
              • hr
                • System.ComponentModel.DataAnnotations.resources.dll
              • hu
                • System.ComponentModel.DataAnnotations.resources.dll
              • id
                • System.ComponentModel.DataAnnotations.resources.dll
              • Images
                • box.png
                • left_box.png
                • left_cloud.png
                • left_oval.png
                • nuebe1.jpg
                • rght_oval.png
                • right_box.png
                • right_cloud.png
              • it
                • System.ComponentModel.DataAnnotations.resources.dll
                • System.ServiceModel.DomainServices.Client.resources.dll
                • System.ServiceModel.DomainServices.Client.Web.resources.dll
                • System.ServiceModel.Web.Extensions.resources.dll
              • ja
                • System.ComponentModel.DataAnnotations.resources.dll
                • System.ServiceModel.DomainServices.Client.resources.dll
                • System.ServiceModel.DomainServices.Client.Web.resources.dll
                • System.ServiceModel.Web.Extensions.resources.dll
              • ko
                • System.ComponentModel.DataAnnotations.resources.dll
                • System.ServiceModel.DomainServices.Client.resources.dll
                • System.ServiceModel.DomainServices.Client.Web.resources.dll
                • System.ServiceModel.Web.Extensions.resources.dll
              • lt
                • System.ComponentModel.DataAnnotations.resources.dll
              • lv
                • System.ComponentModel.DataAnnotations.resources.dll
              • ms
                • System.ComponentModel.DataAnnotations.resources.dll
              • nl
                • System.ComponentModel.DataAnnotations.resources.dll
              • no
                • System.ComponentModel.DataAnnotations.resources.dll
              • pl
                • System.ComponentModel.DataAnnotations.resources.dll
              • pt
                • System.ComponentModel.DataAnnotations.resources.dll
              • pt-BR
                • System.ComponentModel.DataAnnotations.resources.dll
              • ro
                • System.ComponentModel.DataAnnotations.resources.dll
              • ru
                • System.ComponentModel.DataAnnotations.resources.dll
                • System.ServiceModel.DomainServices.Client.resources.dll
                • System.ServiceModel.DomainServices.Client.Web.resources.dll
                • System.ServiceModel.Web.Extensions.resources.dll
              • sk
                • System.ComponentModel.DataAnnotations.resources.dll
              • sl
                • System.ComponentModel.DataAnnotations.resources.dll
              • sr-Cyrl-CS
                • System.ComponentModel.DataAnnotations.resources.dll
              • sr-Latn-CS
                • System.ComponentModel.DataAnnotations.resources.dll
              • sv
                • System.ComponentModel.DataAnnotations.resources.dll
              • System.ComponentModel.DataAnnotations.dll
              • System.ComponentModel.DataAnnotations.xml
              • System.ServiceModel.DomainServices.Client.dll
              • System.ServiceModel.DomainServices.Client.Web.dll
              • System.ServiceModel.DomainServices.Client.Web.xml
              • System.ServiceModel.DomainServices.Client.xml
              • System.ServiceModel.Web.Extensions.dll
              • System.ServiceModel.Web.Extensions.xml
              • th
                • System.ComponentModel.DataAnnotations.resources.dll
              • tr
                • System.ComponentModel.DataAnnotations.resources.dll
              • uk
                • System.ComponentModel.DataAnnotations.resources.dll
              • vi
                • System.ComponentModel.DataAnnotations.resources.dll
              • zh-Hans
                • System.ComponentModel.DataAnnotations.resources.dll
                • System.ServiceModel.DomainServices.Client.resources.dll
                • System.ServiceModel.DomainServices.Client.Web.resources.dll
                • System.ServiceModel.Web.Extensions.resources.dll
              • zh-Hant
                • System.ComponentModel.DataAnnotations.resources.dll
                • System.ServiceModel.DomainServices.Client.resources.dll
                • System.ServiceModel.DomainServices.Client.Web.resources.dll
                • System.ServiceModel.Web.Extensions.resources.dll
          • clases
          • comic.vbproj
          • comic.vbproj.user
          • Generated_Code
          • Images
            • box.png
            • left_box.png
            • left_cloud.png
            • left_oval.png
            • nuebe1.jpg
            • rght_oval.png
            • right_box.png
            • right_cloud.png
            • Thumbs.db
          • MainPage.xaml
          • MainPage.xaml.vb
          • My Project
          • obj
        • Generated_Code
        • Images
          • nube_derecha.png
          • nube_derecha1.png
          • nube_izquierda.png
          • nube_izquierda1.png
          • nuebe1.jpg
          • nuebe1.jpg.png
          • ovalo_derecha1.png
          • ovalo_izquierda1.png
          • rectangulo_derecha1.png
          • rectangulo_izquierdo1.png
          • rectangulo1.png
          • Thumbs.db
        • MainPage.xaml
        • MainPage.xaml.vb
        • My Project
        • obj
Option Explicit On
Imports System.IO
Imports System.Windows.Printing
Imports System.Windows.Media.Imaging
Imports System.Collections.Generic
Imports System.Xml
Imports System.Text
Imports System.IO.IsolatedStorage


Partial Public Class MainPage
    Inherits UserControl

    Private lClouds As New System.Collections.Generic.List(Of cFigure)
    Private iCountClouds As Integer = -1
    Public Shared iActualCloud As Integer
    Public Enum eFigure
        leftCloud
        rightCloud
        leftOval
        rightOval
        leftBox
        rightBox
        Box
    End Enum
    Public Sub New()
        InitializeComponent()
    End Sub
    Private Sub Canvas_Drop(ByVal sender As System.Object, ByVal e As System.Windows.DragEventArgs) Handles MyBase.Drop, box1.Drop, box2.Drop, box3.Drop, box4.Drop, box5.Drop, box6.Drop
        Dim dataObject As IDataObject = e.Data 'For know what is the canvas of the image was dropped
        Dim dropPoint As Point = e.GetPosition(sender) 'For know the position of the image was dropped
        If dataObject.GetDataPresent(DataFormats.FileDrop) Then 'If a file was dropped
            Dim files As FileInfo() = DirectCast(dataObject.GetData(DataFormats.FileDrop), FileInfo()) 'Get the info of the file dropped
            If files.Length > 0 Then
                sender.Children.Clear()
                'A filter to only accept images files (.jpg, .png or gifs)
                If files(0).Extension.ToLower = ".jpg" Or files(0).Extension.ToLower = ".png" Or files(0).Extension.ToLower = ".gif" Then
                    Dim bitmapImage As New System.Windows.Media.Imaging.BitmapImage() 'For copy the image dropped
                    bitmapImage.SetSource(files(0).OpenRead()) 'Copy the image to a bitmap
                    Dim newImage As New Image() 'Create a new image for copy the image
                    'For put the image on the coordinates 0,0
                    dropPoint.Y = 0
                    dropPoint.X = 0
                    'Resize the image to the size of the canvas
                    newImage.Width = sender.Width
                    newImage.Height = sender.Height
                    newImage.Source = bitmapImage
                    newImage.SetValue(Canvas.TopProperty, dropPoint.Y)
                    newImage.SetValue(Canvas.LeftProperty, dropPoint.X)
                    newImage.Stretch = Stretch.Fill
                    'Add the image at the canvas
                    sender.Children.Add(newImage)
                End If
            End If
        End If
    End Sub
    Private Sub Canvas2_MouseLeftButtonDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles canvasComic.MouseLeftButtonDown
        Dim dropPoint As Point = e.GetPosition(canvasComic)
        If lClouds.Count > 0 Then
            lClouds(iActualCloud).bAux = True
            lClouds(iActualCloud).SetPosition(dropPoint)
        End If
    End Sub
    Private Sub Canvas2_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles canvasComic.MouseMove
        If lClouds.Count > 0 Then
            If lClouds(iActualCloud).bAux Then
                Dim dropPoint As Point = e.GetPosition(canvasComic)
                If dropPoint.Y + lClouds(iActualCloud).newImage.Height < canvasComic.Height And dropPoint.X + lClouds(iActualCloud).newImage.Width < canvasComic.Width Then
                    lClouds(iActualCloud).SetPosition(dropPoint)
                End If
            End If
        End If
    End Sub
    Private Sub Canvas2_MouseLeftButtonUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles canvasComic.MouseLeftButtonUp
        If lClouds.Count > 0 Then
            lClouds(iActualCloud).bAux = False
        End If
    End Sub
    Private Function CanvasBeginPrint(ByVal s As Object, ByVal args As Object) As Object
        Return Nothing
    End Function
    Private Function CanvasPrintPage(ByVal s As Object, ByVal args As Object, ByVal dynamicPanel As Canvas) As Object
        args.PageVisual = dynamicPanel
        Return Nothing
    End Function
    Private Function CanvasEndPrint(ByVal s As Object, ByVal args As Object, ByVal dynamicPanel As Canvas) As Object
        dynamicPanel = Nothing ' cleanup
        Return Nothing
    End Function
    Private Sub ComboBox1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles cbBallons.SelectionChanged
        iActualCloud = Me.cbBallons.SelectedIndex
    End Sub
    ''' <summary>
    ''' Set the ballon to draw
    ''' </summary>
    ''' <param name="eFigure">The type of figure</param>
    ''' <remarks></remarks>
    Private Sub SaveFigure(ByVal eFigure As [Enum])
        Dim dropPoint As Point 'The location for the cloud
        Dim iText As Integer 'The number of the ballon
        Dim oCloud As New cFigure() 'The object to save a cloud
        dropPoint.X = 0
        dropPoint.Y = 0
        iCountClouds += 1 'Add a new cloud to the counter
        iText = iCountClouds + 1 'Add the text for the cloud
        iActualCloud = iCountClouds 'Set the actual cloud 
        Me.cbBallons.Items.Add(eFigure.ToString + iText.ToString()) 'Add the ballon to the combobox
        oCloud.SetImage(Me.tbText.Text, dropPoint, eFigure, iCountClouds)
        oCloud.iChildren = Me.canvasComic.Children.Count + 1
        lClouds.Add(oCloud)
        canvasComic.Children.Add(lClouds(oCloud.iNumber).newImage)
        canvasComic.Children.Add(lClouds(oCloud.iNumber).tb)
        Me.tbText.Text = ""
    End Sub

    Private Sub SaveFigure(ByVal type As eFigure, ByVal pPoint As Point)
        Dim dropPoint As Point
        Dim iText As Integer
        Dim oNube As New cFigure()
        dropPoint.X = pPoint.X
        dropPoint.Y = pPoint.Y
        iCountClouds += 1
        iText = iCountClouds + 1
        Me.cbBallons.Items.Add(type.ToString + iText.ToString())
        oNube.SetImage(Me.tbText.Text, dropPoint, type, iCountClouds)
        oNube.iChildren = Me.canvasComic.Children.Count + 1
        lClouds.Add(oNube)
        canvasComic.Children.Add(lClouds(oNube.iNumber).newImage)
        canvasComic.Children.Add(lClouds(oNube.iNumber).tb)
        Me.tbText.Text = ""
    End Sub

    ''' <summary>
    '''Saves to isolated storage
    ''' </summary>
    ''' <param name="buffer">The buffer</param>
    ''' <param name="fileName"></param>
    Private Shared Sub _SaveToDisk(ByVal buffer As Byte(), ByVal fileName As String)
        Using iso As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
            Using stream As New IsolatedStorageFileStream(fileName, FileMode.CreateNew, iso)
                stream.Write(buffer, 0, buffer.Length)
            End Using
        End Using
    End Sub
    ''' <summary>
    '''     Gets the buffer to save to disk from the writable bitmap
    ''' </summary>
    ''' <param name="bitmap">The bitmap image</param>
    ''' <returns>The buffer of bytes</returns>
    Private Shared Function _GetSaveBuffer(ByVal bitmap As WriteableBitmap) As Byte()
        Dim matrixSize As Long = bitmap.PixelWidth * bitmap.PixelHeight
        Dim byteSize As Long = matrixSize * 4 + 4
        Dim retVal As Byte() = New Byte(byteSize - 1) {}
        Dim bufferPos As Long = 0
        retVal(System.Math.Max(System.Threading.Interlocked.Increment(bufferPos), bufferPos - 1)) = CByte((bitmap.PixelWidth / 256) And &HFF)
        retVal(System.Math.Max(System.Threading.Interlocked.Increment(bufferPos), bufferPos - 1)) = CByte((bitmap.PixelWidth Mod 256) And &HFF)
        retVal(System.Math.Max(System.Threading.Interlocked.Increment(bufferPos), bufferPos - 1)) = CByte((bitmap.PixelHeight / 256) And &HFF)
        retVal(System.Math.Max(System.Threading.Interlocked.Increment(bufferPos), bufferPos - 1)) = CByte((bitmap.PixelHeight Mod 256) And &HFF)
        For matrixPos As Integer = 0 To matrixSize - 1
            retVal(System.Math.Max(System.Threading.Interlocked.Increment(bufferPos), bufferPos - 1)) = CByte((bitmap.Pixels(matrixPos) >> 24) And &HFF)
            retVal(System.Math.Max(System.Threading.Interlocked.Increment(bufferPos), bufferPos - 1)) = CByte((bitmap.Pixels(matrixPos) >> 16) And &HFF)
            retVal(System.Math.Max(System.Threading.Interlocked.Increment(bufferPos), bufferPos - 1)) = CByte((bitmap.Pixels(matrixPos) >> 8) And &HFF)
            retVal(System.Math.Max(System.Threading.Interlocked.Increment(bufferPos), bufferPos - 1)) = CByte((bitmap.Pixels(matrixPos)) And &HFF)
        Next
        Return retVal
    End Function

    Private Sub bLeftCloud_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles bLeftCloud.Click
        Me.SaveFigure(eFigure.leftCloud)
    End Sub
    Private Sub bRightCloud_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles bRightCloud.Click
        Me.SaveFigure(eFigure.rightCloud)
    End Sub
    Private Sub bLeftOval_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles bLeftOval.Click
        Me.SaveFigure(eFigure.leftOval)
    End Sub
    Private Sub bRightOval_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles bRightOval.Click
        Me.SaveFigure(eFigure.rightOval)
    End Sub
    Private Sub bLeftBox_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles bLeftBox.Click
        Me.SaveFigure(eFigure.leftBox)
    End Sub
    Private Sub bRightBox_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles bRightBox.Click
        Me.SaveFigure(eFigure.rightBox)
    End Sub
    Private Sub bBox_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles bBox.Click
        Me.SaveFigure(eFigure.Box)
    End Sub

    Private Sub bDelete_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles bDelete.Click
        Me.canvasComic.Children.RemoveAt(lClouds(iActualCloud).iChildren)
        Me.canvasComic.Children.RemoveAt(lClouds(iActualCloud).iChildren - 1)
        Me.lClouds.RemoveAt(iActualCloud)
        Me.cbBallons.Items.RemoveAt(iActualCloud)
        If iActualCloud > 0 Then
            iActualCloud -= 1
        End If
        If iCountClouds >= 0 Then
            iCountClouds -= 1
        End If
    End Sub
    Private Sub bNuevo_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles bNew.Click
        'There are 12 children for the main Canvas, then delete of the childrenx except the first 12
        For i = canvasComic.Children.Count - 1 To 12 Step -1
            Me.canvasComic.Children.RemoveAt(i)
        Next
        If Me.box1.Children.Count > 0 Then
            box1.Children.Clear()
        End If
        If Me.box2.Children.Count > 0 Then
            box2.Children.Clear()
        End If
        If Me.box3.Children.Count > 0 Then
            box3.Children.Clear()
        End If
        If Me.box4.Children.Count > 0 Then
            box4.Children.Clear()
        End If
        If Me.box5.Children.Count > 0 Then
            box5.Children.Clear()
        End If
        If Me.box6.Children.Count > 0 Then
            box6.Children.Clear()
        End If
        Me.cbBallons.Items.Clear()
        iActualCloud = 0
        iCountClouds = -1
        Me.lClouds.Clear()
    End Sub
    Private Sub bAbrir_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles bOpen.Click
        Dim output As StringBuilder = New StringBuilder()
        Dim sfile As String
        Dim iPos As Integer = 0
        Dim oFigure As New cFigure()
        Dim dropPoint As Point

        Using isoStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
            ' Open the file again for reading.
            If isoStore.FileExists("WebComic.xml") Then
                Using readerfile As New StreamReader(isoStore.OpenFile("WebComic.xml", FileMode.Open))
                    sfile = readerfile.ReadToEnd()
                End Using
                Using reader As XmlReader = XmlReader.Create(New StringReader(sfile))
                    Dim ws As XmlWriterSettings = New XmlWriterSettings()
                    ws.Indent = True
                    ' Parse the file and display each of the nodes.
                    Me.lClouds.Clear()
                    iActualCloud = 0
                    iCountClouds = -1
                    While reader.Read()
                        Select Case reader.NodeType
                            Case XmlNodeType.Element
                                Select Case reader.Name
                                    Case "ballon"
                                        iPos += 1
                                    Case "X"
                                        If reader.Read() Then
                                            oFigure.iPosition.X = CInt(reader.Value)
                                            dropPoint.X = oFigure.iPosition.X
                                        End If
                                    Case "Y"
                                        If reader.Read() Then
                                            oFigure.iPosition.Y = CInt(reader.Value)
                                            dropPoint.Y = oFigure.iPosition.Y
                                        End If
                                    Case "Type"
                                        If reader.Read() Then
                                            oFigure.iPosition = dropPoint
                                            oFigure.type = DirectCast([Enum].Parse(GetType(eFigure), reader.Value.ToString, True), eFigure)

                                        End If
                                    Case "Text"
                                        If reader.Read() Then
                                            oFigure.tb.Text = reader.Value
                                            Me.tbText.Text = oFigure.tb.Text
                                            Me.SaveFigure(oFigure.type, dropPoint)
                                            oFigure.SetPosition(dropPoint)
                                            Me.tbText.Text = ""
                                        End If
                                End Select
                            Case XmlNodeType.Text
                            Case XmlNodeType.XmlDeclaration
                            Case XmlNodeType.ProcessingInstruction
                            Case XmlNodeType.Comment
                            Case XmlNodeType.EndElement
                        End Select
                    End While
                End Using
            End If
        End Using
        TextBlock3.Text = output.ToString()
    End Sub
    Private Sub bImprimir_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles bPrint.Click
        ' create an instance of PrintDocument
        Dim document As New PrintDocument()
        ' Add the handlers for print canvasComic is the canvas that contains the box of the page
        AddHandler document.BeginPrint, Function(s, args) CanvasBeginPrint(s, args)
        AddHandler document.PrintPage, Function(s, args) CanvasPrintPage(s, args, canvasComic)
        AddHandler document.EndPrint, Function(s, args) CanvasEndPrint(s, args, canvasComic)
        ' call the Print() with a proper name which will be visible in the Print Queue
        document.Print("Printing Comic")
    End Sub
    Private Sub bGuardar_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles bSave.Click
        Dim iImagen As New Image()
        'If Me.box1.Children.Count > 0 Then
        '    Dim bitmap As New WriteableBitmap(box1, New TransformGroup())
        '    _SaveToDisk(_GetSaveBuffer(bitmap), "c:\test.jpg")
        'End If
        Using isoStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
            ' Create new file
            Using isoStream As IsolatedStorageFileStream = _
                New IsolatedStorageFileStream("WebComic.xml", _
                    FileMode.Create, isoStore)
                ' Write to the Isolated Storage for the user.
                Dim settings As XmlWriterSettings = New XmlWriterSettings()
                settings.Indent = True
                ' Create an XmlWriter.
                Using writer As XmlWriter = XmlWriter.Create(isoStream, settings)
                    writer.WriteComment("Web Comic")
                    writer.WriteStartElement("figures")
                    For i = 0 To lClouds.Count - 1
                        ' Write an element (this one is the root).
                        writer.WriteStartElement("ballon")
                        Dim oGlogo As New cFigure()
                        ' Write an element (this one is the root).
                        writer.WriteElementString("X", lClouds(i).iPosition.X.ToString())
                        writer.WriteElementString("Y", lClouds(i).iPosition.Y.ToString())
                        writer.WriteElementString("Type", lClouds(i).type.ToString())
                        writer.WriteElementString("Text", lClouds(i).tb.Text)
                        writer.WriteEndElement()
                    Next
                    ' Write the close tag for the root element.
                    writer.WriteEndElement()
                    writer.WriteEndDocument()
                    ' Write the XML to the file.
                    writer.Flush()
                End Using
            End Using
        End Using
    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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer armheSistemas
Mexico Mexico
I'm a software developer. I like to develop web pages and desktop systems. I'm learning unity, xamarin, swift, android, security, UX

Comments and Discussions