'//----------------------------------------------------------------------
'//【ラインとイメージの描画】- ImagesAndLines
'//
'//
'//                                                       by Masato Hirai
'//----------------------------------------------------------------------
Imports System
Imports System.Collections
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Reflection
Imports GeniusHirai.ColorfulControls

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 PictureBox1 As System.Windows.Forms.PictureBox
  Friend WithEvents NumericUpDown1 As System.Windows.Forms.NumericUpDown
  Friend WithEvents RichLabel1 As GeniusHirai.ColorfulControls.RichLabel
  Friend WithEvents Button1 As GeniusHirai.ColorfulControls.OvalButton
  Friend WithEvents CheckBox1 As GeniusHirai.ColorfulControls.BigCheckBox
  Friend WithEvents CheckBox2 As GeniusHirai.ColorfulControls.BigCheckBox
  Friend WithEvents NumericLabel1 As GeniusHirai.ColorfulControls.NumericLabel
  Friend WithEvents Label1 As System.Windows.Forms.Label
  Friend WithEvents Label2 As System.Windows.Forms.Label
  Friend WithEvents Button2 As GeniusHirai.ColorfulControls.OvalButton
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.NumericUpDown1 = New System.Windows.Forms.NumericUpDown
Me.RichLabel1 = New GeniusHirai.ColorfulControls.RichLabel
Me.Button1 = New GeniusHirai.ColorfulControls.OvalButton
Me.CheckBox1 = New GeniusHirai.ColorfulControls.BigCheckBox
Me.CheckBox2 = New GeniusHirai.ColorfulControls.BigCheckBox
Me.Button2 = New GeniusHirai.ColorfulControls.OvalButton
Me.NumericLabel1 = New GeniusHirai.ColorfulControls.NumericLabel
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'PictureBox1
'
Me.PictureBox1.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.PictureBox1.BackColor = System.Drawing.Color.Black
Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.PictureBox1.Location = New System.Drawing.Point(16, 72)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(432, 240)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'NumericUpDown1
'
Me.NumericUpDown1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.NumericUpDown1.Font = New System.Drawing.Font("MS UI Gothic", 24.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.NumericUpDown1.Increment = New Decimal(New Integer() {100, 0, 0, 0})
Me.NumericUpDown1.Location = New System.Drawing.Point(496, 120)
Me.NumericUpDown1.Maximum = New Decimal(New Integer() {100000, 0, 0, 0})
Me.NumericUpDown1.Name = "NumericUpDown1"
Me.NumericUpDown1.Size = New System.Drawing.Size(96, 39)
Me.NumericUpDown1.TabIndex = 5
Me.NumericUpDown1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
Me.NumericUpDown1.Value = New Decimal(New Integer() {25, 0, 0, 0})
'
'RichLabel1
'
Me.RichLabel1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.RichLabel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.RichLabel1.Dock = System.Windows.Forms.DockStyle.Top
Me.RichLabel1.Font = New System.Drawing.Font("Arial", 27.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.RichLabel1.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
Me.RichLabel1.Location = New System.Drawing.Point(0, 0)
Me.RichLabel1.Name = "RichLabel1"
Me.RichLabel1.Size = New System.Drawing.Size(608, 56)
Me.RichLabel1.TabIndex = 8
Me.RichLabel1.Text = "Images And Lines"
Me.RichLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'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.Blue
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, 328)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(168, 64)
Me.Button1.TabIndex = 9
Me.Button1.Text = "ライン"
'
'CheckBox1
'
Me.CheckBox1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.CheckBox1.Font = New System.Drawing.Font("MS UI Gothic", 21.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.CheckBox1.Location = New System.Drawing.Point(24, 408)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(224, 32)
Me.CheckBox1.TabIndex = 10
Me.CheckBox1.Text = "FillRectangle"
'
'CheckBox2
'
Me.CheckBox2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.CheckBox2.Font = New System.Drawing.Font("MS UI Gothic", 21.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.CheckBox2.Location = New System.Drawing.Point(264, 408)
Me.CheckBox2.Name = "CheckBox2"
Me.CheckBox2.Size = New System.Drawing.Size(312, 32)
Me.CheckBox2.TabIndex = 11
Me.CheckBox2.Text = "自動スケーリングなし"
'
'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.Blue
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(264, 328)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(168, 64)
Me.Button2.TabIndex = 12
Me.Button2.Text = "イメージ"
'
'NumericLabel1
'
Me.NumericLabel1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.NumericLabel1.BackColor = System.Drawing.Color.Black
Me.NumericLabel1.ForeColor = System.Drawing.Color.Yellow
Me.NumericLabel1.Location = New System.Drawing.Point(456, 248)
Me.NumericLabel1.Name = "NumericLabel1"
Me.NumericLabel1.Size = New System.Drawing.Size(139, 63)
Me.NumericLabel1.TabIndex = 13
Me.NumericLabel1.Text = "NumericLabel1"
Me.NumericLabel1.UpperPoint = 4
Me.NumericLabel1.ZoomMode = GeniusHirai.ColorfulControls.NumericLabel.ZoomModes.Mini
'
'Label1
'
Me.Label1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Label1.Font = New System.Drawing.Font("MS UI Gothic", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.Label1.Location = New System.Drawing.Point(456, 80)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(112, 24)
Me.Label1.TabIndex = 14
Me.Label1.Text = "試行回数："
'
'Label2
'
Me.Label2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Label2.Font = New System.Drawing.Font("MS UI Gothic", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.Label2.Location = New System.Drawing.Point(456, 216)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(112, 24)
Me.Label2.TabIndex = 15
Me.Label2.Text = "速度："
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
Me.ClientSize = New System.Drawing.Size(608, 462)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.NumericLabel1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.CheckBox2)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichLabel1)
Me.Controls.Add(Me.NumericUpDown1)
Me.Controls.Add(Me.PictureBox1)
Me.Name = "Form1"
Me.Text = "イメージとラインの描画"
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

    End Sub

#End Region

  Private iArr(24) As Image

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    For k As Integer = 1 To iArr.Length
      iArr(k - 1) = Image.FromFile("..\Images\" & k.ToString("00") & ".jpg")
    Next
  End Sub

'//
'// ラインの描画
'//
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim t As Integer = Environment.TickCount - t
  Dim isFillRect As Boolean = CheckBox1.Checked
  Dim b As New SolidBrush(Color.White)
  Dim p As New Pen(Color.White)
  p.Width = 2
  p.EndCap = Drawing2D.LineCap.Flat
  p.StartCap = Drawing2D.LineCap.Flat
  Dim g As Graphics = PictureBox1.CreateGraphics
  For k As Integer = 1 To NumericUpDown1.Value
    g.Clear(PictureBox1.BackColor)
    For x As Integer = 0 To PictureBox1.Width Step 40
      For y As Integer = 0 To PictureBox1.Height Step 40

  'ラインの描画
  If isFillRect Then
    g.FillRectangle(b, x - 1, y - 1, 2, PictureBox1.Height)
    g.FillRectangle(b, -1, y - 1, Me.Width, 2)
  Else
    g.DrawLine(p, x, y, x, PictureBox1.Height)
    g.DrawLine(p, x, y, PictureBox1.Width, y)
  End If

      Next
    Next
  Next
  b.Dispose()
  p.Dispose()
  g.Dispose()
  NumericLabel1.Value = Environment.TickCount - t
End Sub

'//
'// イメージの描画
'//
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  Dim t As Integer = Environment.TickCount - t
  Dim NoFlip As Boolean = CheckBox2.Checked
  Dim g As Graphics = PictureBox1.CreateGraphics
  For k As Integer = 1 To NumericUpDown1.Value
    g.Clear(PictureBox1.BackColor)
    For n As Integer = 0 To 24
      If NoFlip Then
        g.DrawImage(iArr(n), 0, 0, iArr(n).Width, iArr(n).Height)
      Else
        g.DrawImage(iArr(n), 0, 0)
      End If
    Next
  Next
  g.Dispose()
  NumericLabel1.Value = Environment.TickCount - t
End Sub


End Class
