none
Button Act like a combo box RRS feed

  • Question

  • hi

    i want 3 or 4 button in a list.  when i click on 1st button it shows sub items.  example

    button days

    button months 

    when press the button days it show the name of days and month button at the end.  simirarly when press month button it show the month. like

    button days

    satureday

    sunday

    ...

    ...

    friday

    month


    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Wednesday, March 20, 2019 7:03 PM

Answers

  • Hi

    Here is what you asked for. Limited to a couple of buttons for Days and a couple for Months.

    If you want to try this out, start a new project, in the Designer, add a Button called Days and a Button called Months and any other catagory Buttons.. Add a Panel1 with all the day buttons and panel2 with all the month buttons. See Designer image below.

    If you choose to go this route, be warned, you will get into difficulties. The previous advice given is a better choice.

    Designer Layout

    Running Image

    Code

    ' Form1 with multiple Buttons
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ExpandDays()
        ExpandMonths()
      End Sub
      Sub ExpandDays()
        Static exp As Boolean = True
        Select Case exp
          Case True
            exp = False
            Panel1.Visible = False
            Months.Location = New Point(Days.Left, Days.Bottom + 8)
          Case Else
            exp = True
            If Panel2.Visible Then ExpandMonths()
            Panel1.Visible = True
            Months.Location = New Point(Days.Left, Panel1.Bottom + 8)
        End Select
        Panel1.Location = New Point(Days.Left, Days.Bottom + 8)
        SetButton3()
      End Sub
      Sub ExpandMonths()
        Static exp As Boolean = True
        Select Case exp
          Case True
            exp = False
            Panel2.Visible = False
            If Panel2.Visible Then ExpandDays()
          Case Else
            exp = True
            If Panel1.Visible Then ExpandDays()
            Panel2.Visible = True
        End Select
        Panel2.Location = New Point(Months.Left, Months.Bottom + 8)
        SetButton3()
      End Sub
      Sub SetButton3()
        If Panel2.Visible Then
          SomeOtherButton.Location = New Point(Months.Left, Panel2.Bottom + 8)
        Else
          SomeOtherButton.Location = New Point(Months.Left, Months.Bottom + 8)
        End If
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Days.Click
        ExpandDays()
      End Sub
      Private Sub Months_Click(sender As Object, e As EventArgs) Handles Months.Click
        ExpandMonths()
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, March 20, 2019 8:17 PM
    • Marked as answer by muhammadanzar Monday, March 25, 2019 6:28 PM
    Wednesday, March 20, 2019 8:16 PM

All replies

  • Why not just use a combo box?  Users know what controls are supposed to do.

    UI Principles


    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    Wednesday, March 20, 2019 7:15 PM
  • Right off the top of my head, I would create a TableLayoutPanel with all buttons involved, then alter the height of the proper ColumnStyles

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Wednesday, March 20, 2019 7:16 PM
  • Hi

    Here is what you asked for. Limited to a couple of buttons for Days and a couple for Months.

    If you want to try this out, start a new project, in the Designer, add a Button called Days and a Button called Months and any other catagory Buttons.. Add a Panel1 with all the day buttons and panel2 with all the month buttons. See Designer image below.

    If you choose to go this route, be warned, you will get into difficulties. The previous advice given is a better choice.

    Designer Layout

    Running Image

    Code

    ' Form1 with multiple Buttons
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ExpandDays()
        ExpandMonths()
      End Sub
      Sub ExpandDays()
        Static exp As Boolean = True
        Select Case exp
          Case True
            exp = False
            Panel1.Visible = False
            Months.Location = New Point(Days.Left, Days.Bottom + 8)
          Case Else
            exp = True
            If Panel2.Visible Then ExpandMonths()
            Panel1.Visible = True
            Months.Location = New Point(Days.Left, Panel1.Bottom + 8)
        End Select
        Panel1.Location = New Point(Days.Left, Days.Bottom + 8)
        SetButton3()
      End Sub
      Sub ExpandMonths()
        Static exp As Boolean = True
        Select Case exp
          Case True
            exp = False
            Panel2.Visible = False
            If Panel2.Visible Then ExpandDays()
          Case Else
            exp = True
            If Panel1.Visible Then ExpandDays()
            Panel2.Visible = True
        End Select
        Panel2.Location = New Point(Months.Left, Months.Bottom + 8)
        SetButton3()
      End Sub
      Sub SetButton3()
        If Panel2.Visible Then
          SomeOtherButton.Location = New Point(Months.Left, Panel2.Bottom + 8)
        Else
          SomeOtherButton.Location = New Point(Months.Left, Months.Bottom + 8)
        End If
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Days.Click
        ExpandDays()
      End Sub
      Private Sub Months_Click(sender As Object, e As EventArgs) Handles Months.Click
        ExpandMonths()
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, March 20, 2019 8:17 PM
    • Marked as answer by muhammadanzar Monday, March 25, 2019 6:28 PM
    Wednesday, March 20, 2019 8:16 PM
  • Check the following custom control

    https://www.codeproject.com/Articles/29822/DropDownPanel-Custom-DropDown-Panel-with-a-Graphic


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, March 20, 2019 9:17 PM
    Moderator
  • Hi,

    Public Class Form1
        Dim t As String = "2019 - 3 - 22"
        Dim ymd As String() = t.Split(New Char() {"/"c, "-"c})
        Dim timeStr As String = ymd(0) & "/" & ymd(1) & "/" & ymd(2) & " 10:00:00"
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            GroupBox1.Visible = If(GroupBox1.Visible = True, False, True)
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            GroupBox1.Visible = False
            Button2.Text = "days"
            Button3.Text = "months"
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            TextBox1.Text = Convert.ToDateTime(timeStr).DayOfWeek.ToString() & " " & Convert.ToDateTime(timeStr).Month.ToString
        End Sub
    
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            TextBox1.Text = Convert.ToDateTime(timeStr).Month.ToString
        End Sub
    
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 22, 2019 7:11 AM
  • You can use a Drop-Down Button


    Friday, March 22, 2019 10:20 AM