|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
For each and form controlsShouldn't this code look at all textboxes on my form and make it lightblue and say "OK"? It seems to be evaluating a button I have on the form and giving me this error "A first chance exception of type 'System.InvalidCastException' occurred in Math.exe" For Each Textbox As System.Windows.Forms.TextBox In Me.Controls Textbox.BackColor = System.Drawing.Color.LightBlue Textbox.Text = "OK" Next Textbox 1st line of trace stack -- which shows that it looked at the button at Math.test.CheckAnswers_Click(Object sender, EventArgs e) in C:\Math\Math\test.vb:line 67 thanks for your help Tony TonyMast wrote:
Show quoteHide quote > win forms - xp pro - vb 2005 No, that tries to convert every control in the form to a textbox.> > > > Shouldn't this code look at all textboxes on my form and make it lightblue > and say "OK"? > It seems to be evaluating a button I have on the form and giving me this > error > > "A first chance exception of type 'System.InvalidCastException' occurred in > Math.exe" > > > For Each Textbox As System.Windows.Forms.TextBox In Me.Controls > Textbox.BackColor = System.Drawing.Color.LightBlue > Textbox.Text = "OK" > Next Textbox > > 1st line of trace stack -- which shows that it looked at the button > at Math.test.CheckAnswers_Click(Object sender, EventArgs e) in > C:\Math\Math\test.vb:line 67 > > > > thanks for your help > Tony > > > For Each C As Control In Me.Controls if typeof C is TextBox then Dim T as Textbox T.BackColor = System.Drawing.Color.LightBlue T.Text = "OK" end if Next C Chris Op Wed, 05 Apr 2006 21:23:50 -0400 schreef Chris:
> No, that tries to convert every control in the form to a textbox. Chris,> > For Each C As Control In Me.Controls > if typeof C is TextBox then > Dim T as Textbox > T.BackColor = System.Drawing.Color.LightBlue > T.Text = "OK" > end if > Next C > > Chris I also always forget to assign C to T:-) Renze de Waal.
Show quote
Hide quote
"Renze de Waal" <re***@dewaal.speedlinq.nl> wrote in message fwiw... VB6 version...news:e8njr3q537fh.w3yiwnwonqtq$.dlg@40tude.net... > Op Wed, 05 Apr 2006 21:23:50 -0400 schreef Chris: > >> No, that tries to convert every control in the form to a textbox. >> >> For Each C As Control In Me.Controls >> if typeof C is TextBox then >> Dim T as Textbox >> T.BackColor = System.Drawing.Color.LightBlue >> T.Text = "OK" >> end if >> Next C >> >> Chris > > Chris, > > I also always forget to assign C to T:-) > > Renze de Waal. Dim C As Control >> For Each C In Controls There'd be no reason to create and assign an additional object variable.... >> if typeof C is TextBox then >> C.BackColor = LightBlue 'your defined constant >> C.Text = "OK" >> end if >> Next unless you want intellisense. -- Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com Please keep all discussions in the groups.. Tony,
Beside the answer from Chris, should you be aware that it does all textboxes direct on your form. A textbox that is in another control in your form is not done. Have a look at this sample how to do recursive. http://www.vb-tips.com/default.aspx?ID=8ff290d4-5c16-4cef-ba06-56e3599238c1 Only the top of the sample. I hope this helps, Cor Show quoteHide quote "TonyMast" <TonyM***@xxxMSNxxx.Com> schreef in bericht news:uKRMW6RWGHA.1900@TK2MSFTNGP04.phx.gbl... > win forms - xp pro - vb 2005 > > > > Shouldn't this code look at all textboxes on my form and make it lightblue > and say "OK"? > It seems to be evaluating a button I have on the form and giving me this > error > > "A first chance exception of type 'System.InvalidCastException' occurred > in Math.exe" > > > For Each Textbox As System.Windows.Forms.TextBox In Me.Controls > Textbox.BackColor = System.Drawing.Color.LightBlue > Textbox.Text = "OK" > Next Textbox > > 1st line of trace stack -- which shows that it looked at the button > at Math.test.CheckAnswers_Click(Object sender, EventArgs e) in > C:\Math\Math\test.vb:line 67 > > > > thanks for your help > Tony > > >
Startup Form's Name
populating variables from dynamically created controls Drawing xor lines multiple selection from checkboxes into text box how do I customize a vb.net deployment project Inherited UserControls do not in appear in Toolbox (VB.NET 2005) VB command line compiler vbc.exe AND type "Int32" is not defined SQL Server Locks/ProcessID - Is this a problem? Textbox 'remembering' previous entries Visual Basic 2005 Express |
|||||||||||||||||||||||