'//----------------------------------------------------------------------
'//【String v.s. StringBuilder】- StringPerform
'//
'//
'//                                                       by Masato Hirai
'//----------------------------------------------------------------------
Imports System
Imports System.Text

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows フォーム デザイナで生成されたコード "

    Public Sub New()
        MyBase.New()

        ' この呼び出しは Windows フォーム デザイナで必要です。
        InitializeComponent()

        ' InitializeComponent() 呼び出しの後に初期化を追加します。

    End Sub

    ' Form は、コンポーネント一覧に後処理を実行するために dispose をオーバーライドします。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' Windows フォーム デザイナで必要です。
    Private components As System.ComponentModel.IContainer

    ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。
    'Windows フォーム デザイナを使って変更してください。  
    ' コード エディタを使って変更しないでください。
  Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  Friend WithEvents Button1 As GeniusHirai.ColorfulControls.OvalButton
  Friend WithEvents Button2 As GeniusHirai.ColorfulControls.OvalButton
  Friend WithEvents Label1 As GeniusHirai.ColorfulControls.RichLabel
  Friend WithEvents NumLabel As GeniusHirai.ColorfulControls.NumericLabel
  Friend WithEvents Button3 As GeniusHirai.ColorfulControls.OvalButton
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New GeniusHirai.ColorfulControls.OvalButton
Me.Button2 = New GeniusHirai.ColorfulControls.OvalButton
Me.Label1 = New GeniusHirai.ColorfulControls.RichLabel
Me.NumLabel = New GeniusHirai.ColorfulControls.NumericLabel
Me.Button3 = New GeniusHirai.ColorfulControls.OvalButton
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
            Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.TextBox1.Font = New System.Drawing.Font("MS UI Gothic", 48.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.TextBox1.Location = New System.Drawing.Point(8, 104)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TextBox1.Size = New System.Drawing.Size(568, 336)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.Button1.FaceColor = GeniusHirai.ColorfulControls.OvalButton.FaceColorConstant.Magenta
Me.Button1.Font = New System.Drawing.Font("MS UI Gothic", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.Button1.Location = New System.Drawing.Point(16, 448)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(224, 72)
Me.Button1.TabIndex = 3
Me.Button1.Text = "String"
'
'Button2
'
Me.Button2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Button2.FaceColor = GeniusHirai.ColorfulControls.OvalButton.FaceColorConstant.Magenta
Me.Button2.Font = New System.Drawing.Font("MS UI Gothic", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.Button2.Location = New System.Drawing.Point(344, 448)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(224, 72)
Me.Button2.TabIndex = 4
Me.Button2.Text = "StringBuilder"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.Label1.Dock = System.Windows.Forms.DockStyle.Top
Me.Label1.Font = New System.Drawing.Font("MS UI Gothic", 27.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(592, 88)
Me.Label1.TabIndex = 4
Me.Label1.Text = "String v.s. StringBuilder"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'NumLabel
'
Me.NumLabel.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.NumLabel.BackColor = System.Drawing.Color.Black
Me.NumLabel.ForeColor = System.Drawing.Color.Yellow
Me.NumLabel.Location = New System.Drawing.Point(408, 16)
Me.NumLabel.Name = "NumLabel"
Me.NumLabel.Size = New System.Drawing.Size(172, 63)
Me.NumLabel.TabIndex = 5
Me.NumLabel.UpperPoint = 5
Me.NumLabel.ZoomMode = GeniusHirai.ColorfulControls.NumericLabel.ZoomModes.Mini
'
'Button3
'
Me.Button3.Anchor = System.Windows.Forms.AnchorStyles.Bottom
Me.Button3.FaceColor = GeniusHirai.ColorfulControls.OvalButton.FaceColorConstant.Red
Me.Button3.Font = New System.Drawing.Font("MS UI Gothic", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.Button3.Location = New System.Drawing.Point(264, 456)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(64, 64)
Me.Button3.TabIndex = 7
Me.Button3.Text = "GC"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(11, 24)
Me.ClientSize = New System.Drawing.Size(592, 534)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.NumLabel)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label1)
Me.Font = New System.Drawing.Font("MS UI Gothic", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.Name = "Form1"
Me.Text = "ガベージコレクション デモ"
Me.ResumeLayout(False)

    End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  TextBox1.Clear()
  Me.Refresh()
  Dim t As Integer = Environment.TickCount
  Dim s As String
  For n As Integer = 1 To 50

    '//
    '// Stringクラスによる文字列の結合
    '//
    For k As Integer = 39770 To 40164
      s = s & System.Convert.ToChar(k)
    Next

  Next
  TextBox1.Text = s
  NumLabel.Value = Environment.TickCount - t
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  TextBox1.Clear()
  Me.Refresh()
  Dim t As Integer = Environment.TickCount
  Dim s As New StringBuilder
  For n As Integer = 1 To 50

    '//
    '// StringBuilderクラスによる文字列の結合
    '//
    For k As Integer = 39770 To 40164
      s.Append(Convert.ToChar(k))
    Next

  Next
  TextBox1.Text = s.ToString
  NumLabel.Value = Environment.TickCount - t
End Sub


  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  End Sub


  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    System.GC.Collect(System.GC.MaxGeneration)
  End Sub

End Class
