| You are here: | About>Computing & Technology>Visual Basic> Using VB.NET> How To Use Resources in Visual Basic .NET |
![]() | Visual Basic |
How To Use Resources in Visual Basic .NETVB.NET Resources - Faster, Smarter, StrongerPart One of this article demonstrated how to use resource files in VB 6. Resource files let you add a bitmap, a wav file, a custom cursor or some other special effect to your Visual Basic project. Microsoft defines them this way, "A resource is any nonexecutable data that is logically deployed with an application." The main advantage of resource files is that they're integrated directly into your Visual Basic project for maximum execution speed and minimum hassle packaging and deploying your application. Although VB 6 has a complete set of tools to add resources, only the main resources: strings, icons, bitmaps, and cursors, have built in processing in Visual Basic 6 and only strings can be created with a built in editor in VB 6. You can include any digital resource in your VB 6 project, but you have to provide your own processing code - typically with a Win32 API call of some sort. With VB.NET, your options are expanded! The resource types that are supported in the Resource Editor are:
Another area where .NET provides better support for resources is in globalization. This was always one reason for using resources, but Microsoft has heard clearly heard the jingling clink of Rupees, Euros, Yen, and Kroner in .NET. In addition to giving you the ability to include resources into your main assembly, .NET also lets you package resources into satellite assemblies for even more flexibility. This is the key for effective globalization because you can include just those satellite assemblies that a particular market somewhere in the world needs. You don't have to "add-in" a special tool to use resources in VB.NET. Resources are one of the properties of the project so all you have to do is display the Properties tabbed dialog for a solution and then select the Resources tab. Since resources are a property of the solution in VB.NET, you access then just like other properties. By name, using the My.Resources object. To make this more clear, let's build the same application we used for VB.6 and display icons for Aristotle's "four elements". To add the elements icons, select Properties for a Solution in Solution Explorer, or select the SolutionName Properties from the Project Menu. Then select the Resources tab. You can add icons to this file by either choosing Add Existing File ... from the Add Resources drop down menu, or just drag and drop from a Windows Explorer window. The code to use the icon resources is very similar to the VB 6 code, but with ALL of the names changed, of course. Here's what the new code looks like: Private Sub RadioButton1_CheckedChanged( ... To download the complete sample application in VB.NET,Click Here. Note that this application was created using VB.NET 2005 and Framework 2.0. This works great when you're using resource files in about the same way that they were used in VB 6, but if you want to take advantage of some of the advanced features, then the resource files have to be converted from .resx files, where they're stored in XML format. For example, here's a snippet from the .resx file we just created: <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Text based XML doesn't work too well in binary files. To convert .resx files (and also .txt files) into common language runtine binary .resources files, use the Resource File Generator (resgen.exe) to convert .resx (or .txt files) into a format that can be embedded in a runtime binary executable or compiled into satellite assemblies. And DOS will never die! You have to run resgen.exe from a Command Prompt line. |
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. |


