Results 1 to 7 of 7

Thread: [RESOLVED] Change label location

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    40

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Change label location

    You can get a reference to the control like so:
    vb.net Code:
    1. Me.Controls("txt" & pcname)
    You then change its location by changing its Location, as you do in the designer.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    40

    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

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

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    40

    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?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Change label location

    Are the Labels on the form directly, or are they on some other container, e.g. a Panel?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    40

    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
  •  



Click Here to Expand Forum to Full Width