| You are here: | About>Computing & Technology>Visual Basic> Using VB.NET> Changing Properties "On The Fly" |
![]() | Visual Basic |
Changing Properties "On The Fly"Sep 22 2007 Change how your program works while it's running!When Von Neumann created modern programming with his "stored program concept" in 1945, one of the original revolutionary concepts was that sometimes a program could be considered instructions and sometimes data. When a program loop updates a counter, for example, part of the program source code (the loop counter) is updated "on the fly". Similarly, if a program statement changes TextBox.Text, you're also updating your program source at runtime. Properties in general can be updated while the program is running. VB.NET provides a collection that is very useful in processing controls at runtime: the Me.Controls collection. The basic idea is to code a loop with this For statement. For Each <control> As Control In Me.Controls Using this collection, all controls on a form can be checked and properties updated. If only some of the controls need to be changed, check the TypeOf <control> or the Name of the control. The programs below illustrate the concepts by using a Timer control to change the display every second. If you want to duplicate the programs on your own system, create standard Windows Applications with the controls required by the code. You can get the names of the controls from the source code. The Timer properties are: Timer1.Enabled = True The first program below sets the BackColor property to a random color value and also randomly hides controls using the Visible property. The end result for three of the generated forms can be seen in the illustration. -------- Public Class Form1 The second program is a variation on a technique familiar to VB 6 programmers: stacking controls in the same space. See it on the next page in a new format. |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


