|
-
Feb 27th, 2010, 07:34 PM
#1
Thread Starter
Member
[RESOLVED] Change label location
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
-
Feb 27th, 2010, 07:42 PM
#2
Re: Change label location
You can get a reference to the control like so:
vb.net Code:
Me.Controls("txt" & pcname)
You then change its location by changing its Location, as you do in the designer.
-
Feb 27th, 2010, 07:59 PM
#3
Thread Starter
Member
Re: Change label location
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
-
Feb 27th, 2010, 08:08 PM
#4
Re: Change label location
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.
-
Feb 27th, 2010, 08:27 PM
#5
Thread Starter
Member
Re: Change label location
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
Code:
PB(i).Name = item.SubItems(0).Text.Replace("-", "")
txt(i).Name = "txt" & item.SubItems(0).Text.Replace("-", "")
I even added in a msgbox to see what I was getting and got "txtS11" and "S11"
the picbox is the picturebox that is being clicked on
Any ideas?
-
Feb 27th, 2010, 08:32 PM
#6
Re: Change label location
Are the Labels on the form directly, or are they on some other container, e.g. a Panel?
-
Feb 27th, 2010, 08:37 PM
#7
Thread Starter
Member
Re: Change label location
Oh my god I'm an idiot. Sorry Thanks for your help.
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
|