Results 1 to 10 of 10

Thread: [RESOLVED] hide show button

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Resolved [RESOLVED] hide show button

    vb Code:
    1. Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    2.         Dim i As Integer = 0
    3.         If ComboBox1.SelectedIndex = 1 Then
    4.             Do Until i = 80
    5.                 Select Case True
    6.                     Case i < 70
    7.                         Dim tempButton As Button = DirectCast(Me.Controls("qmb_" & i), Button)
    8.                         tempButton.Visible = False
    9.                     Case i > 70
    10.                         Dim tempButton As Button = DirectCast(Me.Controls("qmb_" & i), Button)
    11.                         tempButton.Visible = True
    12.                 End Select
    13.                 i += 1
    14.             Loop
    15.         Else
    16.             Do Until i = 80
    17.                 Select Case True
    18.                     Case i < 70
    19.                         Dim tempButton As Button = DirectCast(Me.Controls("qmb_" & i), Button)
    20.                         tempButton.Visible = True
    21.                     Case i > 70
    22.                         Dim tempButton As Button = DirectCast(Me.Controls("qmb_" & i), Button)
    23.                         tempButton.Visible = False
    24.                 End Select
    25.                 i += 1
    26.             Loop
    27.         End If
    28.     End Sub

    is there an easy way to do it or better code than mine because this is just a simple there will be like 400 button and to show and hide every 70 will be long code

  2. #2
    Addicted Member
    Join Date
    Jan 2012
    Location
    Athens, Greece
    Posts
    143

    Re: hide show button

    If you want to hide or show every 70 buttons you could check

    i mod 140

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: hide show button

    Quote Originally Posted by pkarvou View Post
    If you want to hide or show every 70 buttons you could check

    i mod 140
    what is i mod 140 sorry i'm new to programing

  4. #4
    Addicted Member
    Join Date
    Jan 2012
    Location
    Athens, Greece
    Posts
    143

    Re: hide show button

    Mod is the modulo of a division

    For example think 34/5 then

    34 = 6*5 + 4 --> mod = 4
    Last edited by pkarvou; Jan 28th, 2012 at 11:48 AM.

  5. #5
    Addicted Member
    Join Date
    Jan 2012
    Location
    Athens, Greece
    Posts
    143

    Re: hide show button

    Code:
    Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim i As Integer
        For i = 1 to 400 
            Dim tempButton As Button = DirectCast(Me.Controls("qmb_" & i), Button)
            tempButton.visible = ((ComboBox1.SelectedIndex = 1) And (i Mod 140 > 70))
                Or ((ComboBox1.SelectedIndex <> 1) And (i Mod 140 < 70))
        Next
    End Sub
    What about this?
    Last edited by pkarvou; Jan 28th, 2012 at 12:01 PM.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: hide show button

    Quote Originally Posted by pkarvou View Post
    Code:
    Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim i As Integer
        For i = 1 to 400 
            Dim tempButton As Button = DirectCast(Me.Controls("qmb_" & i), Button)
            tempButton.visible = ((ComboBox1.SelectedIndex = 1) And (i Mod 140 > 70))
                Or ((ComboBox1.SelectedIndex <> 1) And (i Mod 140 < 70))
        Next
    End Sub
    What about this?
    your code mean that only bottons from 351 to 400 will be visable..how that will help me show and hide buttons 70 by 70
    Last edited by new1; Jan 28th, 2012 at 05:52 PM.

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: hide show button

    here's a simplified example that uses 14 buttons + hides/shows buttons 1-7 + 8-14 when you change the combobox item. this will only work in vb2010:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    4.         If ComboBox1.SelectedIndex = 0 Then
    5.             Array.ForEach(Enumerable.Range(1, 7).ToArray, Sub(x) Me.Controls("Button" & x.ToString).Visible = True)
    6.             Array.ForEach(Enumerable.Range(8, 7).ToArray, Sub(x) Me.Controls("Button" & x.ToString).Visible = False)
    7.         Else
    8.             Array.ForEach(Enumerable.Range(1, 7).ToArray, Sub(x) Me.Controls("Button" & x.ToString).Visible = False)
    9.             Array.ForEach(Enumerable.Range(8, 7).ToArray, Sub(x) Me.Controls("Button" & x.ToString).Visible = True)
    10.         End If
    11.     End Sub
    12.  
    13.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    14.         ComboBox1.SelectedIndex = 0
    15.     End Sub
    16.  
    17. End Class

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: hide show button

    Quote Originally Posted by .paul. View Post
    here's a simplified example that uses 14 buttons + hides/shows buttons 1-7 + 8-14 when you change the combobox item. this will only work in vb2010:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    4.         If ComboBox1.SelectedIndex = 0 Then
    5.             Array.ForEach(Enumerable.Range(1, 7).ToArray, Sub(x) Me.Controls("Button" & x.ToString).Visible = True)
    6.             Array.ForEach(Enumerable.Range(8, 7).ToArray, Sub(x) Me.Controls("Button" & x.ToString).Visible = False)
    7.         Else
    8.             Array.ForEach(Enumerable.Range(1, 7).ToArray, Sub(x) Me.Controls("Button" & x.ToString).Visible = False)
    9.             Array.ForEach(Enumerable.Range(8, 7).ToArray, Sub(x) Me.Controls("Button" & x.ToString).Visible = True)
    10.         End If
    11.     End Sub
    12.  
    13.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    14.         ComboBox1.SelectedIndex = 0
    15.     End Sub
    16.  
    17. End Class
    hmmm nice paul but i did it in other way tell me what do you think about the code and which are better and why yours or mine..i want you to tell me which better cause i want to learn hwo to code better

    vb Code:
    1. Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    2. Dim i As Integer
    3.         For i = 0 To 79
    4.             Dim tempButton As Button = DirectCast(Me.Controls("qmb_" & i), Button)
    5. tempButton.Visible = ((ComboBox1.SelectedIndex = 0) And (i > 69)) Or ((ComboBox1.SelectedIndex = 1) And (i <= 69))
    6. Next
    7. End Sub

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: hide show button

    i prefer my method because it's easier to read, but if your (pkarvou's) method works, then it's ok.

  10. #10
    Addicted Member
    Join Date
    Jan 2012
    Location
    Athens, Greece
    Posts
    143

    Re: hide show button

    Quote Originally Posted by new1 View Post
    your code mean that only bottons from 351 to 400 will be visable..how that will help me show and hide buttons 70 by 70
    If i < 140
    Example i = 65 then i = 0*140 + 65 mod = 65 visible if SelectionIndex <> 1

    if 140<i<280
    Example i = 226 then i=1*140 + 77 mod = 86 visible if SelectionIndex = 1

    if i > 280
    Example i = 311 then i = 2*140 + 31 mod = 31 visible if SelectionIndex <> 1


    So on each occasion your result will be between 0 and 140 so you cab check visibility

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width