' Copyright (C) 2025  P4pillon.org
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as
' published by the Free Software Foundation, either version 3 of the
' License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program.  If not, see <https://www.gnu.org/licenses/>.
Public Class MyCombobox
    Public Show_items_Form As Show_items
    Public Shared FlowLayoutPanel_nbr_lignes As Integer
    Public Shared MyCombobox_ScreenPos As Point
    Public Shared MyCombobox_size As Size
    Public Sub MyCombobox_Click(sender As Object, e As EventArgs) Handles Me.Click
        If Me.Items.Count = 0 Or Me.Items.Count > 20 Then
            Exit Sub
        End If
        FlowLayoutPanel_nbr_lignes = System.Math.Floor(System.Math.Sqrt(Me.Items.Count)) * 2




        MyCombobox_ScreenPos = Me.PointToScreen(New Point(0, 0))
        MyCombobox_size = Me.Size

        Show_items_Form = New Show_items
        'Show_items_Form.BackColor = Me.BackColor
        Show_items_Form.Back_Button.BackColor = Me.BackColor
        Show_items_Form.Back_Button.ForeColor = Me.ForeColor
        Show_items_Form.FlowLayoutPanel1.BackColor = Me.BackColor
        For r = 0 To Me.Items.Count - 1
            Dim but As New Button
            but.Text = Me.Items.Item(r).ToString
            but.ForeColor = Me.ForeColor
            but.BackColor = Me.BackColor
            but.Size = New Size(200, 50)
            but.Padding = New Padding(1, 1, 1, 1)
            but.Margin = New Padding(0)
            but.FlatStyle = Windows.Forms.FlatStyle.Flat
            but.FlatAppearance.BorderSize = 1

            'but.Font = Me.Font
            but.Font = New Font(Me.Font.FontFamily.ToString, 14)
            AddHandler but.Click, AddressOf butclik
            Show_items_Form.FlowLayoutPanel1.Controls.Add(but)
        Next
        AddHandler Show_items_Form.Back_Button.Click, AddressOf Back_Button_Click
        'Show_items_Form.Location = MyCombobox_ScreenPos
        Show_items_Form.Location = New Point(MyCombobox_ScreenPos.X + MyCombobox_size.Width, MyCombobox_ScreenPos.Y)
        'Show_items_Form.ShowDialog()
        Show_items_Form.Visible = True
    End Sub
    Public Sub butclik(sender As Object, e As EventArgs)
        Show_items_Form.Visible = False
        Me.Text = sender.Text
        Show_items_Form.Close()
    End Sub
    Private Sub Back_Button_Click(sender As Object, e As EventArgs)
        Show_items_Form.Visible = False
        Me.Text = ""
        Show_items_Form.Close()
    End Sub
End Class
