Results 1 to 8 of 8

Thread: Problem with my project

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2020
    Posts
    59

    Question Problem with my project

    So In my program I’ve putted a flowlayourpanel and with a button I add to the layout infinite new buttons
    (button.name = “button” + i.tostring) [i = i + 1]
    With another button I want to hide the button with the i=3 so button3.hide(), but it doesn’t work beacause it doesn’t exist yet so How can I refer to the button created when the i was 3?

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

    Re: Problem with my project

    Try this...

    Code:
    Dim x As Integer = 3
    Me.FlowLayoutPanel1.Controls("Button" & x.ToString).Hide()

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2020
    Posts
    59

    Re: Problem with my project

    Quote Originally Posted by .paul. View Post
    Try this...

    Code:
    Dim x As Integer = 3
    Me.FlowLayoutPanel1.Controls("Button" & x.ToString).Hide()

    Thanks I will try it tomorrow and let u know

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Problem with my project

    Quote Originally Posted by .paul. View Post
    Try this...

    Code:
    Dim x As Integer = 3
    Me.FlowLayoutPanel1.Controls("Button" & x.ToString).Hide()
    Just a small thing for the record: you don't need the ToString in that case. It's not wrong and may be considered to add clarity but the concatenation operator always widens its operands to type String so any and every time it is used to already know that both operands will be converted to a String if they can be. Any operands that cannot be widened to type String cannot be used with the concatenation operator and would require an explicit conversion.

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2020
    Posts
    59

    Thumbs up Re: Problem with my project

    Quote Originally Posted by .paul. View Post
    Try this...

    Code:
    Dim x As Integer = 3
    Me.FlowLayoutPanel1.Controls("Button" & x.ToString).Hide()


    Perfect it did work

    One more thing: I set x = senderX.name that is the button witch I click to hide the other one and all works

    I click button “1” and the “button1” hides I click button “2” and the “button2” hides but now I want that when I hide the (“button” & x.toSting) x= 2 I want that all the other buttons shows.
    How can I do this?


    I thought like me.flowlayoutpanel.controls( control.name.contains “button”).show exept me.flowlayoutpanel.controls(“button” & x.tostring) X=SenderX

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

    Re: Problem with my project

    Code:
    For each b as Button in FlowLayoutPanel1.Controls.OfType(of Button)
        b.Visible = True
    Next
    ‘ now All buttons are visible hide your selected button here

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2020
    Posts
    59

    Re: Problem with my project

    Quote Originally Posted by .paul. View Post
    Code:
    For each b as Button in FlowLayoutPanel1.Controls.OfType(of Button)
        b.Visible = True
    Next
    ‘ now All buttons are visible hide your selected button here
    thank u very mutch

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2020
    Posts
    59

    Re: Problem with my project

    Quote Originally Posted by .paul. View Post
    Code:
    For each b as Button in FlowLayoutPanel1.Controls.OfType(of Button)
        b.Visible = True
    Next
    ‘ now All buttons are visible hide your selected button here
    thank u very mutch

Tags for this Thread

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