Results 1 to 6 of 6

Thread: Reset label/textbox to design time value

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Sydney
    Posts
    311

    Resolved Reset label/textbox to design time value

    Hi

    Something I've oddly never thought about until today.

    I have a label, it's design time text is 'My Label'.

    At run time, that text is changed to 'New text'.

    At run time, can I get the original value of the text 'My Label' from the control itself, i.e. 'My Label? Yes I could use variables etc or the tag, but is there an easier way?

    I see there is Label1.ResetText which resets the text to its default value, what is its default value and where/how is it set?

    Ta
    Last edited by Help321; Jan 13th, 2015 at 05:19 PM.
    Why do today what you can tomorrow...

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,399

    Re: Reset label/textbox to design time value

    The default value relates to the Property Datatype, which as a Label.Text is Type String, is ""

  3. #3
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Reset label/textbox to design time value

    To retain your 'design time' string, you will need to store that value in a variable. If you look at the designer file, all the designer is doing is setting the specific text for the label.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,241

    Re: Reset label/textbox to design time value

    Right. There's no magic going on in the designer. It's probably worth looking at the .designer.vb file, as you will see that all the stuff you do in the designer is just turned into .NET code that is the same as code you could write. In fact, I have an app that was largely created without the IDE by a generator. I also have an app where there are forms that can't be displayed in the designer. Neither of these are issues, because the forms are really created by code.

    The other thing you would note from the .designer.vb file is that the text set in the designer is nothing special. It isn't stored or used in any way that suggests that it came from the designer as opposed to anywhere else.

    The question gets asked every other month or so, and the answer is always the same: If you want to reset your form back to how it was when first shown, you have to do it yourself. There isn't normally any shortcut.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Sydney
    Posts
    311

    Re: Reset label/textbox to design time value

    Thanks all. I've always used variables to do this. It just dawned on me today that there really should be an easier way. At run time it knows what the original value is, so there's no reason why there couldn't be a Label1.ResetTextToOriginal function to save messing about.

    So I thought I'd ask the question just in case I'd been missing something after all these years.
    Why do today what you can tomorrow...

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,241

    Re: Reset label/textbox to design time value

    Well, you could make one as an extension, but it's probably more work than it is worth. MS could have created the property such that it stored the first value set for the property, then allowed restoration through a method. That would have added a very small cost for a seldom used benefit. From what I have seen, when the benefit is not high, MS doesn't create framework code that incurrs additional cost.
    My usual boring signature: Nothing

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