vb.net - How would I use a for loop to edit multiple labels in Visual basic for visual studios -
here code:
private sub button1_click(sender object, e eventargs) handles button1.click dim randval integer dim label string dim val integer dim stringval string integer = 1 256 step 1 val = stringval = cstr(val) label = "label" + stringval randval = cint(math.floor((20 - 1 + 1) * rnd())) + 1 label.backcolor = color.green next end sub
i error string has no property backcolor.
how able edit strings without calling them individually?
the error message correct: there isn't property called backcolor on string.
there backcolor property on button, however, , looks if you're perhaps trying set background color of button object when it's clicked. if so, need hold of button object before can set color. event handler has made (moderately) easy, passing object handler parameter "sender". problem it's sent object, not button, first have cast type want, this:
dim button button button = directcast(sender, button)
then later on can set color:
button.backcolor = color.green
also, if want set text of button, have set using button.text property:
button.text = "what want see on button"
however, you're program hard follow. can't see code why you're executing loop, or why you're setting values randval aren't being used, , it's hard give concrete advice.
Comments
Post a Comment