Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > All labels in form


Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2006, 12:17 PM
SNWBRDR SNWBRDR is offline
Newcomer
 
Join Date: Jan 2006
Posts: 6
Default All labels in form


How can I clean up all labels/textboxes/pictureboxes in my form ?

I thougt this code would work but I seems it doesn't

Dim tTemp As TextBox

For Each tTemp In frmMain
tTemp.Text = ""
Next

Dim lTemp As Label

For Each lTemp In frmMain
lTemp.Text = ""
Next

Dim pTemp As PictureBox

For Each pTemp In frmMain
pTemp.Image = Nothing
Next
Reply With Quote
  #2  
Old 02-02-2006, 05:03 PM
drognir's Avatar
drognir drognir is offline
Centurion
 
Join Date: Nov 2005
Posts: 105
Default

You've got the idea right, but I'd do something like this:
Code:
Dim tTemp As Control For Each tTemp In Me.Controls If TypeOf tTemp Is TextBox Then tTemp.Text = "" ElseIf TypeOf tTemp Is Label Then tTemp.Text = "" End If
EDIT: Original code was in vb6, it's .net now. Also, picturebox part didn't work. Working to fix it now.

Last edited by drognir; 02-02-2006 at 05:14 PM.
Reply With Quote
  #3  
Old 02-03-2006, 10:14 AM
SNWBRDR SNWBRDR is offline
Newcomer
 
Join Date: Jan 2006
Posts: 6
Default

It doesn't work as well ..

And part with the PicturesBoxes gives an error if I try it like this


Dim Temp As Control

For Each Temp In Me.Controls

If TypeOf Temp Is TextBox Or TypeOf Temp Is Label Then

Temp.Text = ""

'ElseIf TypeOf Temp Is PictureBox Then

' Temp.Image = Nothing

End If

Next
Reply With Quote
  #4  
Old 02-03-2006, 10:21 AM
Sonreir's Avatar
Sonreir Sonreir is offline
Contributor
 
Join Date: Jul 2004
Location: Hampshire, England
Posts: 540
Default

Image isn't a default property of System.Windows.Forms.Control.
Try this:
Code:
DirectCast(Temp, PictureBox).Image = Nothing
Reply With Quote
  #5  
Old 02-03-2006, 10:22 AM
anthony_n's Avatar
anthony_n anthony_n is offline
Senior Contributor
 
Join Date: May 2005
Location: Manchester,England
Posts: 1,293
Default

Code:
Dim Temp As Control Dim picBox As PictureBox For Each Temp In Me.Controls If TypeOf Temp Is TextBox Or TypeOf Temp Is Label Then Temp.Text = "" ElseIf TypeOf Temp Is PictureBox Then picBox = Temp picBox.Image = Nothing End If Next End Sub

you have to do a cast from the control to the pic box. here is the long way
__________________
ADO TUTOR

File IO Tutor
Reply With Quote
  #6  
Old 02-04-2006, 12:24 PM
SNWBRDR SNWBRDR is offline
Newcomer
 
Join Date: Jan 2006
Posts: 6
Default

Thanx!

But when I actullay run it, it still doesn't work .. it doesn't do it but I get no errors as well.
Reply With Quote
  #7  
Old 02-04-2006, 03:27 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

What are you using now and what event is it in?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->