You can identify different options for upgraded .NET application advancement depending on the category of the application; this chapter is mainly focused on two of them: Windows applications and forms smart client, and business applications (.NET enterprise services). You will learn how to take advantage of new technologies and updated features, such as .NET ClickOnce deployment, the VB.NET Docking and Anchoring forms control property, the VB .NET Error Provider control, the FlowLayoutPanel and the TableLayoutPanel. The suggestions provided should help you make the most of the Visual Basic .NET and .NET Framework in general from an application-category perspective.
Smart clients are easily deployed and managed client applications that provide an adaptive, responsive and rich interactive experience by leveraging local resources and intelligently connecting to distributed data sources. They are connected systems (usually through the Internet) that allow the user’s local applications to work together with remote applications. They have the ability to work offline, the capability to be deployed and updated in real time over the network from a centralized server, to support multiple platforms and languages because they are built on Web Services, and to run on almost any device that has Internet connectivity.
If a client application displays these 3 features, it can be said to be a smart client:
Visual Basic 6.0 requires you to write custom code for the Resize event to make sure that controls are correctly displayed on the resized form. This makes it possible for any resizable application to retain the original placement of controls on the form regardless of the size of the form itself.
In VB .NET you can accomplish the same result by working with the Docking and Anchoring properties of the controls in your forms. A control’s Anchor property can be modified so that it is dynamically positioned on screen. When a control is anchored to a form, and the form’s size changes, the control’s position on the form remains the same relative to the anchor position(s) it holds. The Docking property of a control allows it to adhere to the edge of the form or the container in which it resides.
Many controls in Visual Basic 6.0 that enhanced the GUI of an application were available by means of importing ActiveX libraries. Many of these components are automatically migrated to .NET by the Visual Basic Upgrade Wizard, but not to their intrinsic counterparts in Visual Basic .NET. Instead, they are converted to ActiveX components.
Note: there’s an enhanced enterprise version of this migration tool, called the Visual Basic Upgrade Companion, that converts additional commonly used ActiveX controls to Windows Forms controls that offer similar functionality, and promotes the use of .NET native libraries when possible, instead of VB Compatibility libraries.
Even though most of the ActiveX controls upgraded from VB 6.0 will work fine when upgraded to VB .NET, you might be better off substituting them for native Windows Forms controls. You can make your project easier to maintain by removing references to ActiveX controls that are not imperative to use. Furthermore, by removing the references, you do not have to worry about their distribution and registration when they are installed on the user’s machine. In most cases, the task of programming native Windows controls is easier than everything that is involved with ActiveX control programming.
Requesting input from a user in your application always involves the risk of a user entering invalid information, so you must have input validation in your code to alert the user. In Visual Basic 6.0, the most common way to perform this task was to use the MsgBoxfunction. The biggest drawback with using a message box to display an error is that in some occasions, a text message is insufficient. For example, if a form has many input fields and there are several errors made, chances are that the user will not remember all the errors after the message box is closed. This means that the user will have to be reminded of the errors more than once to correct the problems with the input.
In Visual Basic .NET, the ErrorProvider control will display an icon to let the user know exactly what and where the problem is. When the mouse is placed over the error notification icon, a ToolTip will be displayed to further assist with the error resolution procedure.
In Visual Studio 2005, two new containers are available that facilitate control placement: the FlowLayoutPanel and the TableLayoutPanel. These controls differ from the Panel container control that was previously available in the way in which controls are placed within it. The two new controls offer full customization for how and where you would like your contained controls to be displayed.
The FlowLayoutPanel makes it easy to automatically position controls when they are added to the container. When controls are added to the panel, they will flow horizontally and vertically to fit within the container. This makes it quick in situations where you would like to deal with perfectly aligned tuples of several controls (for example, several text boxes and labels). You can change the order in which controls flow by changing the values of the FlowDirection property.
The TableLayoutPanel control offers a row-column approach by which to arrange your controls. A noticeable difference is that only one control can be placed in each of the cells in the panel.
Applications created with the .NET Framework version 1.0 will not support themes, but starting with the version 1.1, Windows XP visual styles are available. This behavior will be supported when Visual Studio 2005 ships because every form that is created will support themes by default.
Changing your Visual Basic .NET application’s code so that it supports themes can be done by following two approaches: invoking the EnableVisualStyles static method or using a manifest file. The first one causes all controls in your application to be drawn using visual styles, so it is important to call this method before any controls are drawn. The second one produces a file that includes information that will let your application know which version of the common controls library to use. By specifying that the application should use version 6.0 of the common controls library, you can be assured that all your controls will be drawn according to the selected theme. You will have to save the file with the same name of your application and append the extension “.manifest”, placing it in the same directory where the executable resides. You also have to set the Flatstyle property for any control System.
Each of the options previously mentioned have their own strengths and weaknesses. The manifest file does not involve writing code in your application to work, but using it risks having the user delete the manifest file and render your application themeless. The EnableVisualStyles procedure is easy to implement, but it requires the modification of your source code.
Both Visual Basic 6.0 and Visual Basic .NET support mechanisms to produce different presentations of your application for different languages. Using a single code base, you can distribute versions of your application in English, Spanish, and any other language you want.
In VB 6.0, if you plan to dynamically determine what language your application will run in, you must call some Win32 functions to determine the current locale. In Visual Basic .NET, this same information can be read from the CultureInfo object in the current thread.
In Visual Basic 6.0, resource files are used to store the language specific data that your application uses. This data can be strings, images, or other types of resources. A VB 6.0 project can only contain a single resource file.
One way to add localization features to your application is to place versions of all your data for the different supported languages in a single resource file. Alternatively, you can store each language in different resource files; the resource files are compiled into independent DLLs. At run time, you dynamically load the DLL that contains the localized resources you need.
Visual Studio .NET provides a much more integrated level of support for localization. If you set the Localizable property of your form to True, Visual Studio creates a resource file for that form and stores the text strings for different languages in separate resource files that are automatically compiled into satellite DLLs. These DLLs are loaded dynamically and automatically at run time, depending on the current locale of the user’s computer. Alternatively, and for more control, you can do all this manually if you have to.
Visual Studio .NET does not provide any direct support for adding images to these resource files; however, the .NET Framework SDK provides the source code for a resource editor named ResEditor that does support images. Alternatively, you can embed all the images into the main assembly as resources.
In Visual Basic 6.0, you could associate a ToolTip with a control by setting the ToolTipText property of that control. To disable the ToolTips for a form, it was necessary to go through all the controls in that form and set their ToolTipText properties to the empty string. Without using Win32 calls, this was about the extent of the functionality that was available to VB 6.0 programmers.
In VB .NET, each form has its own ToolTip component. ToolTips are attached to controls by calling the SetToolTip() method of the ToolTip component. Additionally, in Visual Basic .NET, some new possibilities for easily customizing the behavior of your ToolTips are available.
In VB. NET, you can disable all the ToolTips in a form with a single command. The Active property determines whether the ToolTips register in this ToolTip component are displayed. Also, to change the amount of time that the mouse must remain still over a control before the ToolTip is displayed, you can modify the ToolTip.InitialDelay property (default time is half a second). And to change the amount of time that the ToolTip remains visible after it displays, change the AutoPopDelay property, which is set to five seconds by default. However, the ToolTip will disappear immediately after the mouse leaves the region the ToolTip applies to. Finally, a property named ReshowDelay determines the length of time it takes for subsequent ToolTips to appear as the pointer moves around the form.
A separate property can be used to set all of the ToolTip delay properties appropriately. This property is named AutomaticDelay and when you set this property, the same value is automatically copied into the InitialDelay property, a value that is ten times as large is placed in the AutoPopDelay property, and finally, a value that is one fifth as large is copied into the ReshowDelay property.
.NET provides enterprise services for building highly scalable solutions. From the code itself, you can set properties required for enterprise services components or even deployment settings can be settled from the code. This is a great advantage for developers because you have the possibility of handling all those settings within the code.
Enterprise Services divides COM+ catalog properties into two categories:
Enterprise Services is a powerful technology that is very useful when building complex applications that require specific technologies such as transactions, pooling, or queuing.
One of the most confusing aspects of Enterprise Services is when to use them. If your existing systems use COM+ extensively, you should use Enterprise Services when upgrading your applications to .NET.
To create a .NET class for an enterprise service component, the class must derive from the System.ServicedComponent class to exploit COM+ services. To do this, it is necessary to import the .NET Enterprise Services namespace. For some special purpose .NET namespaces, it is necessary to add a new reference to the corresponding assembly because that they are not included by default. This is the case for the System.EnterpriseServices namespace, so a reference to the associated assembly must be added.
COM+ manages threads for you. Every COM component has a ThreadingModel attribute that you can specify when you develop the component. This property determines how the component’s objects are assigned to threads for method execution.
Threads can be associated with two possible types of apartments:
The different types of processes can be defined as follows:
In reality, all processes are apartment model processes, and some apartments have a single thread while others have multiple threads. The threading model applies to an apartment, not to a process. It can also apply to a class of objects, but not a component, such as a DLL; instead, it applies to the object classes within the DLL. Different classes in a DLL can have different threading models.
A process can use both the apartment and free-threaded models, as long as it uses only one free-threaded apartment. It can have more than one single threaded apartment. Invocations to objects in the STAs will be automatically synchronized by Win32 and data will have to be marshaled whenever an apartment barrier is crossed.
The transaction features of COM+ are a repackaging of MTS. COM+ provides a new interface with individual get/set methods for each bit: SetComplete, EnableCommit, SetAbort, and DisableCommit.
Distributed transactions can also be thought of as automatic or declarative transactions in .NET. Performance is only one aspect of the decision making process related to your strategy for transaction management in your application. The other considerations are ease of development and flexibility and future expansion.
If you use a SqlTransaction object or OleDbTransaction object to manage transactions, you are going to have to manage the transaction yourself. You must consider how you will flow that transaction between objects and which object will be the root of the transaction responsible for calling Commit or Rollback.
Please note that the .NET Framework version 2.0 includes a new transaction programming paradigm. This functionality is included in the System.Transactions namespace and provides features such as asynchronous work, events, security, concurrency management, and interoperability.
Another important point to consider is the flexibility of the application. If the system was built from the ground up using Enterprise Services to provide transaction management, it will automatically manage and flow the transaction between all the resource managers, whether they are SQL databases or other transactional resources such as message queues. Additionally, with Enterprise Services you can create a component that participates in a distributed transaction using the Compensating Resource Manager (CRM). This provides new opportunities for executing business logic when the transaction outcome is known.
Message Queuing (also known as MSMQ) constitutes a platform that supports flexible and reliable communication between applications. A task is asynchronously invoked when it is called without waiting for it to terminate and produce a result.
Using this type of execution allows applications to have better responsiveness and improved usage of the available resources. This mode of processing can be achieved using COM+ Queued Components and Message Queuing.
If you want to create a queued component in your application, first declare the interface that you want to call asynchronously through queued components and put the InterfaceQueuing attribute on the interface. The methods of this interface must not use any return values or ByRef arguments.
Your queued interface must be declared as public, or it will not be included in the registration of the assembly with COM+. Also, you have to specify that this assembly will be a queued component, by using the ApplicationQueuing attribute. After that you must provide an implementation of this interface in a server application. The ApplicationQueuing attribute instructs the server application to listen on a queue.
8834 N Capital of Texas Hwy, Ste 302
Austin, TX 78759
Call us: +1 (425) 609-8458
info@wearegap.com