Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reseting the text in a control.

Reseting the text in a control.

Scheduled Pinned Locked Moved C#
comxml
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DELETEUSER
    wrote on last edited by
    #1

    In a windows form I have a textbox and a button. Initially the text box contains "Enter ID" as the default text. I enter some ID and click the button which saves the ID to an XML. After that, the text in the textbox should revert back to "Enter ID" as before. Right now my code is a below... // Windows Form Designer generated code // First time I intialize the dafault text this.txtbox1.Text = "Enter ID"; // Button_click private void button1_Click(object sender, System.EventArgs e) { //Write To File and reset all textboxes on the form for default text SaveToXML(); ResetAllTextBoxes(); } // Reset all text boxes on the window private void ResetAllTextBoxes() { this.textbox1.Text = "Enter ID"; .... .... this.textbox10.Text = "There has to be some another way" } I'm not satisfied with this implementation because if I have 10 textboxes I need to have 20 lines of code doing the same. 10 lines in the Windows Form Designer generated code and 10 in ResetAllTextBoxes() method. I tried the textbox1.ResetText() method but instead of reseting it to default text such as "Enter ID" it resets to blank. Is there a better solution. Thanks ---------- Venus Patel http://patelsinc.blogspot.com/ A student knows little about a lot. A professor knows a lot about little. I know everything about nothing. -- modified at 17:25 Tuesday 10th January, 2006

    C G 2 Replies Last reply
    0
    • D DELETEUSER

      In a windows form I have a textbox and a button. Initially the text box contains "Enter ID" as the default text. I enter some ID and click the button which saves the ID to an XML. After that, the text in the textbox should revert back to "Enter ID" as before. Right now my code is a below... // Windows Form Designer generated code // First time I intialize the dafault text this.txtbox1.Text = "Enter ID"; // Button_click private void button1_Click(object sender, System.EventArgs e) { //Write To File and reset all textboxes on the form for default text SaveToXML(); ResetAllTextBoxes(); } // Reset all text boxes on the window private void ResetAllTextBoxes() { this.textbox1.Text = "Enter ID"; .... .... this.textbox10.Text = "There has to be some another way" } I'm not satisfied with this implementation because if I have 10 textboxes I need to have 20 lines of code doing the same. 10 lines in the Windows Form Designer generated code and 10 in ResetAllTextBoxes() method. I tried the textbox1.ResetText() method but instead of reseting it to default text such as "Enter ID" it resets to blank. Is there a better solution. Thanks ---------- Venus Patel http://patelsinc.blogspot.com/ A student knows little about a lot. A professor knows a lot about little. I know everything about nothing. -- modified at 17:25 Tuesday 10th January, 2006

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      No. You have to write the code to change the values, and the auto generated code will stay the same. Personally, I would not set the values in the forms designer, but just in a method, and call the method after InitializeComponents is called, just to put it all in one place. Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • D DELETEUSER

        In a windows form I have a textbox and a button. Initially the text box contains "Enter ID" as the default text. I enter some ID and click the button which saves the ID to an XML. After that, the text in the textbox should revert back to "Enter ID" as before. Right now my code is a below... // Windows Form Designer generated code // First time I intialize the dafault text this.txtbox1.Text = "Enter ID"; // Button_click private void button1_Click(object sender, System.EventArgs e) { //Write To File and reset all textboxes on the form for default text SaveToXML(); ResetAllTextBoxes(); } // Reset all text boxes on the window private void ResetAllTextBoxes() { this.textbox1.Text = "Enter ID"; .... .... this.textbox10.Text = "There has to be some another way" } I'm not satisfied with this implementation because if I have 10 textboxes I need to have 20 lines of code doing the same. 10 lines in the Windows Form Designer generated code and 10 in ResetAllTextBoxes() method. I tried the textbox1.ResetText() method but instead of reseting it to default text such as "Enter ID" it resets to blank. Is there a better solution. Thanks ---------- Venus Patel http://patelsinc.blogspot.com/ A student knows little about a lot. A professor knows a lot about little. I know everything about nothing. -- modified at 17:25 Tuesday 10th January, 2006

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        You could make your own custom textbox that inherits the built in textbox, and that has a DefaultText property. To easily reset all textboxes, keep a static Arraylist in the class, where each textbox adds a reference to itself when it is created. Then add a static method to the class that loops through the Arraylist and resets the text of each textbox. --- b { font-weight: normal; }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups