Click here to Skip to main content
15,911,030 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to clear all textboxes on a form with a button Pin
KaptinKrunch9-Mar-08 16:57
KaptinKrunch9-Mar-08 16:57 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:05
Jacob Dixon9-Mar-08 17:05 
GeneralRe: How to clear all textboxes on a form with a button Pin
KaptinKrunch9-Mar-08 17:10
KaptinKrunch9-Mar-08 17:10 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:20
Jacob Dixon9-Mar-08 17:20 
GeneralRe: How to clear all textboxes on a form with a button Pin
Christian Graus9-Mar-08 17:35
protectorChristian Graus9-Mar-08 17:35 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:42
Jacob Dixon9-Mar-08 17:42 
GeneralRe: How to clear all textboxes on a form with a button Pin
Christian Graus9-Mar-08 19:28
protectorChristian Graus9-Mar-08 19:28 
GeneralRe: How to clear all textboxes on a form with a button Pin
KaptinKrunch9-Mar-08 17:48
KaptinKrunch9-Mar-08 17:48 
Both examples work under a button click event.
<br />
            foreach (Control txt in this.Controls)<br />
            {<br />
                if (txt.GetType() == typeof(System.Windows.Forms.TextBox))<br />
                {<br />
                    TextBox txtbx = (TextBox)txt;<br />
                    txtbx.Text = "";<br />
                }<br />
            } <br />
<br />
<br />
            for (int i = 0; i < this.Controls.Count; i++)<br />
            {<br />
                if (this.Controls[i] is TextBox)<br />
                {<br />
                    this.Controls[i].Text = "";<br />
                }<br />
            }


Difference between the two is that the first refers to a Control object. So you need to cast it to the TextBox control to gain access to the TextBox property?. Otherwise your setting the text of the control. Check it out in the debugger! In the second you reference the actual object and this exposes the objects, in this case a TextBox, .Text property.

Hope this helps.

Just because we can; does not mean we should.

AnswerRe: How to clear all textboxes on a form with a button Pin
Christian Graus9-Mar-08 17:41
protectorChristian Graus9-Mar-08 17:41 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:48
Jacob Dixon9-Mar-08 17:48 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:51
Jacob Dixon9-Mar-08 17:51 
AnswerRe: How to clear all textboxes on a form with a button Pin
Ravenet9-Mar-08 17:50
Ravenet9-Mar-08 17:50 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:54
Jacob Dixon9-Mar-08 17:54 
GeneralRe: How to clear all textboxes on a form with a button Pin
Ravenet9-Mar-08 17:58
Ravenet9-Mar-08 17:58 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 18:03
Jacob Dixon9-Mar-08 18:03 
GeneralRe: How to clear all textboxes on a form with a button Pin
Ravenet9-Mar-08 18:07
Ravenet9-Mar-08 18:07 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:58
Jacob Dixon9-Mar-08 17:58 
GeneralRe: How to clear all textboxes on a form with a button Pin
Christian Graus9-Mar-08 18:01
protectorChristian Graus9-Mar-08 18:01 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 18:08
Jacob Dixon9-Mar-08 18:08 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 18:10
Jacob Dixon9-Mar-08 18:10 
GeneralRe: How to clear all textboxes on a form with a button Pin
Ravenet9-Mar-08 18:13
Ravenet9-Mar-08 18:13 
QuestionTimer Pin
nelsonpaixao9-Mar-08 15:56
nelsonpaixao9-Mar-08 15:56 
GeneralRe: Timer Pin
Ravenet9-Mar-08 16:33
Ravenet9-Mar-08 16:33 
QuestionDictionary Reset? Pin
Jammer9-Mar-08 13:43
Jammer9-Mar-08 13:43 
GeneralRe: Dictionary Reset? Pin
Christian Graus9-Mar-08 15:01
protectorChristian Graus9-Mar-08 15:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.