My in Different Applications

Now that you know how My can be customized, you can easily understand why different kinds of Visual Basic applications have their own customizations, provided by the IDE. For example, Windows Forms applications provide a My.Forms property that allows access to forms instances, as follows:

Dim oneForm As Form1 = My.Forms.Form1

This is mainly due to the support offered in code by the My namespace to the Application Framework feature. This feature allows executing special tasks at the beginning and at the end of the application lifetime, such as showing splash screens or establishing what form is the main application form. In Windows Forms applications the application framework is enabled by default, and you can get in touch with it by opening My Project and selecting the Application tab, as shown in Figure 20.9.

Figure 20.9 The application framework designer for Windows Forms applications.

image

Enabling the application framework allows visually managing features with no lines of code, although you are allowed to customize the related auto-generated code. For example, the following line manually establishes that My.Settings has to be saved when the application shuts down:

My.Application.SaveMySettingsOnExit = True

The following line shows instead how you can set the minimum number of milliseconds for a splash screen to be shown:

My.Application.MinimumSplashScreenDisplayTime = 1000

For WPF applications the application framework is slightly different, as shown in Figure 20.10.

Figure 20.10 The application framework for WPF applications.

image

The following lines show how you can take advantage of My.Application in WPF to retrieve some information:

image

Generally all members are self-explanatory, so IntelliSense can be a great friend to you in this situation, too. In both Windows Forms and WPF applications, the View Application Events button redirects you to the appropriate file for defining application events (Application.xaml.vb in WPF and Application.Designer.vb in Win Forms). For web applications, Silverlight applications do not support the My namespace whereas ASP.NET applications do not offer the My.Application and My.WebServices members; they instead expose the My.Response and My.Request properties that respectively wrap members from System.Web.HttpResponse and System.Web.HttpRequest.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.89.34