-
Apr 16th, 2018, 10:01 AM
#1
Thread Starter
Lively Member
[RESOLVED] Loop buttons to add an image
I have 20 buttons with a stop sign as the image. I am cleaning up the code in my program and want to reduce lines Below is how I assign an image to each button.
Code >>>
Button01.Image = My.Resources.Stopsign
Button02.Image = My.Resources.Stopsign
Button03.Image = My.Resources.Stopsign
...
Button20.Image = My.Resources.Stopsign
End Code <<<
I got the brilliant idea of using a for...next loop to add images to the buttons:
Code>>>
dim Sign_Img(20)
For x = 1 To 20
Sign_Img(x) = "Button" & x.ToString().PadLeft(2, "0")
Dim newSignstring As String = String.Concat(Sign_Img(x), ".Image = My.Resources.Stopsign")
newsignstring
Next x
End Code <<<
I am getting the "expression is not a method" error. Is it possible to do what I want to do? I think I could do this if I dynamically added buttons, but I am too far in the program to dynamically add the buttons.
Thanks
Carroll
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|