'//----------------------------------------------------------------------
'//【SuspendLayoutのデモ】- ResizeDemo
'//
'//
'//                                                       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
Imports System.Threading

Public Class MainForm : Inherits Form

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

    Public Sub New()
        MyBase.New()

        ' この呼び出しは Windows フォーム デザイナで必要です。
        InitializeComponent()
    For k As Integer = 0 To 24
      pic(k) = New PictureBox
      pic(k).SizeMode = PictureBoxSizeMode.StretchImage
      pic(k).BorderStyle = BorderStyle.Fixed3D
      pic(k).Image = Image.FromFile((k + 1).ToString("00") & ".jpg")
    Next
    Me.Controls.AddRange(pic)
    DrawPicture()
        ' 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 RichLabel1 As GeniusHirai.ColorfulControls.RichLabel
  Friend WithEvents NumericLabel1 As GeniusHirai.ColorfulControls.NumericLabel
  Friend WithEvents CheckBox1 As GeniusHirai.ColorfulControls.BigCheckBox
  Friend WithEvents Button1 As GeniusHirai.ColorfulControls.OvalButton
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.RichLabel1 = New GeniusHirai.ColorfulControls.RichLabel
Me.NumericLabel1 = New GeniusHirai.ColorfulControls.NumericLabel
Me.CheckBox1 = New GeniusHirai.ColorfulControls.BigCheckBox
Me.Button1 = New GeniusHirai.ColorfulControls.OvalButton
Me.SuspendLayout()
'
'RichLabel1
'
Me.RichLabel1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.RichLabel1.Dock = System.Windows.Forms.DockStyle.Top
Me.RichLabel1.Font = New System.Drawing.Font("MS UI Gothic", 27.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.RichLabel1.Location = New System.Drawing.Point(0, 0)
Me.RichLabel1.Name = "RichLabel1"
Me.RichLabel1.Size = New System.Drawing.Size(728, 120)
Me.RichLabel1.TabIndex = 0
Me.RichLabel1.Text = "Resize Demo"
'
'NumericLabel1
'
Me.NumericLabel1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top 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(544, 8)
Me.NumericLabel1.Name = "NumericLabel1"
Me.NumericLabel1.Size = New System.Drawing.Size(172, 63)
Me.NumericLabel1.TabIndex = 1
Me.NumericLabel1.Text = "NumericLabel1"
Me.NumericLabel1.UpperPoint = 5
Me.NumericLabel1.ZoomMode = GeniusHirai.ColorfulControls.NumericLabel.ZoomModes.Mini
'
'CheckBox1
'
Me.CheckBox1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.CheckBox1.BackColor = System.Drawing.Color.Transparent
Me.CheckBox1.Font = New System.Drawing.Font("MS UI Gothic", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.CheckBox1.Location = New System.Drawing.Point(464, 72)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(256, 40)
Me.CheckBox1.TabIndex = 2
Me.CheckBox1.Text = "SuspendLayout"
'
'Button1
'
Me.Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Button1.FaceColor = GeniusHirai.ColorfulControls.OvalButton.FaceColorConstant.Gray
Me.Button1.Font = New System.Drawing.Font("MS UI Gothic", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
Me.Button1.Location = New System.Drawing.Point(368, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 80)
Me.Button1.TabIndex = 3
Me.Button1.Text = "AUTO"
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
Me.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.ClientSize = New System.Drawing.Size(728, 486)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.NumericLabel1)
Me.Controls.Add(Me.RichLabel1)
Me.Name = "MainForm"
Me.Text = "リサイズのパフォーマンス"
Me.ResumeLayout(False)

    End Sub

#End Region

  Dim pic(24) As PictureBox

  Private isDrawing As Boolean = False

'//
'// リサイズ イベント
'//
Private Sub MainForm_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
  If CheckBox1.Checked Then
    If isDrawing Then Return
    isDrawing = True

    Me.SuspendLayout()
    AddHandler Application.Idle, AddressOf App_Idle

  Else
    DrawPicture()   '描画メソッド
  End If
End Sub

'//
'// アイドル イベント
'//
Private Sub App_Idle(ByVal sender As Object, ByVal e As System.EventArgs)
  RemoveHandler Application.Idle, AddressOf App_Idle
  DrawPicture()   '描画メソッド
  Me.ResumeLayout()
  isDrawing = False
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

  If Me.CheckBox1.Checked Then Me.SuspendLayout()

  Me.Width = Screen.PrimaryScreen.WorkingArea.Width \ 2
  Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) \ 2
  Do While Me.Width <= Screen.PrimaryScreen.WorkingArea.Width
    Me.Width += 24
    Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) \ 2
    Me.Refresh()
  Loop

  If Me.CheckBox1.Checked Then Me.ResumeLayout()

  NumericLabel1.Value = Environment.TickCount - t
End Sub


Private Sub DrawPicture()
  Dim newSize As New Size(Me.ClientSize.Width \ 5, (Me.ClientSize.Height - RichLabel1.Height) \ 5)
  Try
    For k As Integer = 24 To 0 Step -1
      pic(k).Location = New Point((k Mod 5) * newSize.Width, (k \ 5) * newSize.Height + RichLabel1.Height)
      pic(k).Size = newSize
      Me.Invalidate()
    Next
  Catch ex As Exception
  End Try
  Thread.Sleep(150)
End Sub

End Class
