Hey
I'm dealing with labels that are created out of the designer then assigned the name "txt" & pcname
How can I change its location ?
any help is appreicated
Thanks
Printable View
Hey
I'm dealing with labels that are created out of the designer then assigned the name "txt" & pcname
How can I change its location ?
any help is appreicated
Thanks
You can get a reference to the control like so:You then change its location by changing its Location, as you do in the designer.vb.net Code:
Me.Controls("txt" & pcname)
thanks for the help. I think I've done something wrong though
I get an error on
Code:Dim usrname As Label = Me.Controls("txt" & picbox.Name.ToString)
usrname.Location = New Point(10, 10)
Object reference not set to an instance of an object.
you dont happen toknow what I'm doing wrong?
thanks again
My first question would be, why do you have a Label with a name starting with "txt"? That would be an appropriate prefix for a TextBox but a Label should be "lbl" or the like. If the prefixes aren't descriptive then they are useless. If they are misleading then they're worse than useless.
Secondly, if the Name property of 'picbox' is a string then there's not much point calling ToString on it, although it won't hurt.
As for the issue, what does picbox.Name contain? Do you really have a Label with the same name as 'picbox' but with a "txt" prefix? Presumably not if you're getting that error message. If you want to get a control by name then you have to use the name of that control.
YIn this case The prefix is not missleading and I am fine with it being txt. But I dont see how my prefix relate at all to my question in the first place.
It should be there, when I create it I rename it to that
I even added in a msgbox to see what I was getting and got "txtS11" and "S11"Code:PB(i).Name = item.SubItems(0).Text.Replace("-", "")
txt(i).Name = "txt" & item.SubItems(0).Text.Replace("-", "")
the picbox is the picturebox that is being clicked on
Any ideas?
Are the Labels on the form directly, or are they on some other container, e.g. a Panel?
Oh my god I'm an idiot. Sorry Thanks for your help.