Public Class ToolPanel
    Inherits System.Windows.Forms.UserControl

    Event ToolChanged(ByVal NewTool As SelectedTool)
    Event LineColorChanged(ByVal NewColor As Color)
    Event FillColorChanged(ByVal NewColor As Color)

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

    Public Sub New()
        MyBase.New()

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

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

    End Sub

    'UserControl はコンポーネント一覧を消去するために 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 Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
    Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton5 As System.Windows.Forms.ToolBarButton
    Friend WithEvents LineColor As System.Windows.Forms.Panel
    Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog
    Friend WithEvents FillColor As System.Windows.Forms.Panel
    Friend WithEvents LineColNone As System.Windows.Forms.CheckBox
    Friend WithEvents FillColNone As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.LineColNone = New System.Windows.Forms.CheckBox
        Me.LineColor = New System.Windows.Forms.Panel
        Me.FillColor = New System.Windows.Forms.Panel
        Me.FillColNone = New System.Windows.Forms.CheckBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.ToolBar1 = New System.Windows.Forms.ToolBar
        Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton5 = New System.Windows.Forms.ToolBarButton
        Me.ColorDialog1 = New System.Windows.Forms.ColorDialog
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 224)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(40, 16)
        Me.Label1.TabIndex = 6
        Me.Label1.Text = "線の色"
        '
        'LineColNone
        '
        Me.LineColNone.Location = New System.Drawing.Point(56, 272)
        Me.LineColNone.Name = "LineColNone"
        Me.LineColNone.Size = New System.Drawing.Size(64, 24)
        Me.LineColNone.TabIndex = 7
        Me.LineColNone.Text = "線なし"
        '
        'LineColor
        '
        Me.LineColor.BackColor = System.Drawing.Color.Black
        Me.LineColor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.LineColor.Location = New System.Drawing.Point(72, 224)
        Me.LineColor.Name = "LineColor"
        Me.LineColor.Size = New System.Drawing.Size(48, 40)
        Me.LineColor.TabIndex = 8
        '
        'FillColor
        '
        Me.FillColor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.FillColor.Location = New System.Drawing.Point(72, 312)
        Me.FillColor.Name = "FillColor"
        Me.FillColor.Size = New System.Drawing.Size(48, 40)
        Me.FillColor.TabIndex = 11
        '
        'FillColNone
        '
        Me.FillColNone.Location = New System.Drawing.Point(56, 360)
        Me.FillColNone.Name = "FillColNone"
        Me.FillColNone.Size = New System.Drawing.Size(64, 24)
        Me.FillColNone.TabIndex = 10
        Me.FillColNone.Text = "塗りなし"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 312)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 16)
        Me.Label2.TabIndex = 9
        Me.Label2.Text = "塗りの色"
        '
        'ToolBar1
        '
        Me.ToolBar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3, Me.ToolBarButton4, Me.ToolBarButton5})
        Me.ToolBar1.ButtonSize = New System.Drawing.Size(100, 32)
        Me.ToolBar1.Dock = System.Windows.Forms.DockStyle.None
        Me.ToolBar1.DropDownArrows = True
        Me.ToolBar1.Location = New System.Drawing.Point(24, 16)
        Me.ToolBar1.Name = "ToolBar1"
        Me.ToolBar1.ShowToolTips = True
        Me.ToolBar1.Size = New System.Drawing.Size(104, 167)
        Me.ToolBar1.TabIndex = 12
        '
        'ToolBarButton1
        '
        Me.ToolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton1.Tag = GraphicsSample._Const.SelectedTool.Line
        Me.ToolBarButton1.Text = "直線"
        '
        'ToolBarButton2
        '
        Me.ToolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton2.Tag = GraphicsSample._Const.SelectedTool.Box
        Me.ToolBarButton2.Text = "四角形"
        '
        'ToolBarButton3
        '
        Me.ToolBarButton3.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton3.Tag = GraphicsSample._Const.SelectedTool.Circle
        Me.ToolBarButton3.Text = "円"
        '
        'ToolBarButton4
        '
        Me.ToolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton4.Tag = GraphicsSample._Const.SelectedTool.Text
        Me.ToolBarButton4.Text = "テキスト"
        '
        'ToolBarButton5
        '
        Me.ToolBarButton5.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton5.Tag = GraphicsSample._Const.SelectedTool.Bitmap
        Me.ToolBarButton5.Text = "画像"
        '
        'ToolPanel
        '
        Me.Controls.Add(Me.ToolBar1)
        Me.Controls.Add(Me.FillColor)
        Me.Controls.Add(Me.FillColNone)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.LineColor)
        Me.Controls.Add(Me.LineColNone)
        Me.Controls.Add(Me.Label1)
        Me.Name = "ToolPanel"
        Me.Size = New System.Drawing.Size(144, 448)
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
        ' ツールバーのボタンが押された
        If e.Button.Pushed = True Then
            ' 押されたとき
            ' 押されたボタン以外は戻す
            For Each btn As ToolBarButton In ToolBar1.Buttons
                If Not btn Is e.Button Then
                    btn.Pushed = False
                End If
            Next
            ' 選択されたツールの変更
            RaiseEvent ToolChanged(CType(e.Button.Tag, SelectedTool))
        Else
            ' 離されたとき
            ' ツールなしにする
            RaiseEvent ToolChanged(SelectedTool.None)
        End If
    End Sub

    Public Sub ToolButtonReset()
        ' ツールバーの状態をリセットする
        For Each btn As ToolBarButton In ToolBar1.Buttons
            btn.Pushed = False
        Next
    End Sub

    Private Sub LineColor_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles LineColor.Paint

    End Sub

    Dim _LineCol, _FillCol As Color

    Public Property LineCol() As Color
        Get
            Return _LineCol
        End Get
        Set(ByVal Value As Color)
            _LineCol = Value
            LineColor.BackColor = _LineCol
            If _LineCol.IsEmpty() Then
                LineColNone.Checked = True
            Else
                LineColNone.Checked = False
            End If
            RaiseEvent LineColorChanged(_LineCol)
        End Set
    End Property

    Public Property FillCol() As Color
        Get
            Return _FillCol
        End Get
        Set(ByVal Value As Color)
            _FillCol = Value
            FillColor.BackColor = _FillCol
            If _FillCol.IsEmpty() Then
                FillColNone.Checked = True
            Else
                FillColNone.Checked = False
            End If
            RaiseEvent FillColorChanged(_FillCol)
        End Set
    End Property

    Private Sub LineColor_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles LineColor.DoubleClick
        ' 線の色変更
        ColorDialog1.Color = LineCol
        If ColorDialog1.ShowDialog() = DialogResult.OK Then
            LineCol = ColorDialog1.Color
        End If
    End Sub


    Private Sub FillColor_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles FillColor.DoubleClick
        ' 塗りの色変更
        ColorDialog1.Color = FillCol
        If ColorDialog1.ShowDialog() = DialogResult.OK Then
            FillCol = ColorDialog1.Color
        End If
    End Sub

    Private Sub LineColNone_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LineColNone.CheckedChanged
        If DirectCast(sender, CheckBox).Checked Then
            ' 線なし
            LineCol = Color.Empty
        Else
            ' 線あり
            If LineCol.IsEmpty() Then
                LineCol = Color.Black
            End If
        End If
    End Sub

    Private Sub FillColNone_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles FillColNone.CheckedChanged
        If DirectCast(sender, CheckBox).Checked Then
            ' 塗りなし
            FillCol = Color.Empty
        Else
            ' 塗りあり
            If FillCol.IsEmpty() Then
                FillCol = Color.White
            End If
        End If
    End Sub
End Class
