[Translation] Visual Basic 2005 Enhancements in Language (2) My

xiaoxiao2021-03-06  42

One of the main challenges faced from Visual Basic 6.0 or even earlier, the development personnel faced by the .NET platform is the large size of the .NET framework itself and a wide range of naming spaces. The applications that are often used and environment variables can be found in the .NET framework, BCL (Base Class Library, 淌 淌.) Can be skilled. It takes time. This new MY level in Visual Basic 2005 provides convenient and organized access interfaces for many frequently used framework libraries, thereby accelerating and simplifying the development of applications.

MY has two amazing features:

* Subsidiary items provide shortcuts for organized ordered access framework libraries.

* A series of dynamic objects can be created when you add forms, settings, resources, and Web services you to your project.

My shortcut is essentially shortcuts that visit the BCL objects that are often used. The top MY shortcut has my.application, my.computer, and my.user, each of which contains its own object level. For example, my.user object is exposed

Audio,

FileSystem,

KEYBOARD,

Mouse,

NetWork,

Registry, etc.:

DIM SVAR

AS

String

svar =

My.user.Identity.name

svar =

My.computer.info.omfullname

svar =

My.application.commandlineargs.count.tostring

When you add forms, resources, settings, and web services to your project, Visual Basic automatically populates your MY objects. My.Resources and My.Settings are especially interesting, because when you add resources and settings in your project, the Visual Basic compiler generates a strong type of variable reference.

Double click in Solution Explorer

My Project items Displays the application editor. As shown in Figure 2, click on the left column of the entry.

Settings.

Figure 2 shows the application editor for setting a table. Error list surface panels are used to display errors, warnings, and other information and have been separated from the task list.

Add a user scope of Integer type setting name MaxInputValue and assign it to it. This way you can immediately enable a strong type variable by intelligent in your code, just like Figure 3.

Figure 3 An example of an exemplified sensation of setting values ​​you created in the Settings Editor. In the upper right corner of the setup editor, there is a labeling

View Code's link. Click this link to see a named MySetting_User.vb. This file is a part class, you can add code processing settings, so when your settings change, your application is updated (see

Part of the type to get more content).

Partial

Public

Class MySettings

'...

End

Class

Three events were exposed in MySettings:

PropertyChanged

Settingchanging

Settingsaving

The interface for the application is

Fill, which means you can store your custom settings by implementing the regular history of these events.

You can also get the stronger type you add resources to your project. If you drag and drop a picture called happy.bmp

Resources editor

In your image workspace, you can use the code like My.Resources.happy to reference it. Happy is a bitmap variable type, so you don't have to use it in your code by casting an Object or Image variable. When you knock in the code, you can effectively effectively quickly. Such as: picturebox1.image =

My.Resources.happy

This line of code gives this bitmap variable to a Picturebox

Image properties. You can look at the window shown in the smart sensation pop-up in Figure 4, which tells you that this object is bitmap type.

Figure 4 Drag and drop a bitmap image to the resource table of the editing application, you can generate a strong type variable, you can reference it in your code.

Add a form and web service in the project,

My variables are always constantly updating the default power type instance in one, and they can be referenced in your code.

As you can see, My can make you more quickly find applications and its environment and BCL-related classes, and allow you to access settings, resources, and others in the project in a simple, strong type of access. Object. These features will greatly increase the development efficiency regardless of any level of Visual Basic developers.

@ 附 上 上 原 文 文 参 参 参 参

MyA major challenge faced by developers migrating to .NET from Visual Basic 6.0 and earlier versions is the sheer size of the .NET Framework and the number of classes in its namespace hierarchy. Commonly used application and environment objects are found throughout the Base Class Library ( BCL) of the .NET Framework, and it takes time to learn their locations. The new My hierarchy in Visual Basic 2005 speeds up and simplifies application development by providing convenient, logically organized access to many commonly used framework classes.

My Comes in Two Flavors:

• Items That Provide Well-Organized Shortcuts Into The Framework Classes.

• a Set of Dynamic Objects Created As you add forms, Settings, Resources, and Web Services to your projects.

The My shortcuts are essentially a speed dial into many commonly used BCL objects. The top-level My shortcuts are My.Application, My.Computer, and My.User, each of which contains its own object hierarchy. For example, the My. User Object Exposes

Audio,

FileSystem,

KEYBOARD,

Mouse,

NetWork,

Registry, and more:

DIM SVAR

AS

String

svar =

My.user.Identity.name

svar =

My.computer.info.omfullnamesvar =

My.application.commandlineargs.count.tostring

The dynamic My objects are automatically populated by Visual Basic as you add forms, resources, settings, and Web services to your project. My.Resources and My.Settings are particularly interesting, as the Visual Basic compiler generates strongly typed variable references as you add Resources and settings to your provject.

Double-Click The

My Project Item in Solution Explorer to Bring Up The Application Designer. Click ON

Settings in the Tab List on The Left Side As Demonstrated in Figure 2.

Figure 2. Application Designer Showing The Settings Tab. The Error List Pane Shows Errors, Warnings, and Messages and is now Separate from the task list.

Add a setting name such as MaxInputValue of type Integer at User scope with a value of 100. You can immediately refer to this setting with a strongly typed object in your code with full IntelliSense as shown in Figure 3.

Figure 3. EXAMPLE OF THE IntelliSense Pop-Up for a Settings Value You Create In The Settings Application Designer

At The Top Right Corner of The Settings Designer Is a Link Labled

View Code. Click on this link to view the file named MySettings_user.vb. This file is a partial class where you can add code to handle settings events to update the state of your application as your settings change (see the section on

Partial Types for more information:

Partial

Public

Class MySettings

'...

End

Class

Three MySettings Events Are Exposed Here:

• PropertyChanged

• SettingChanging

• Settingssaving

The Application Settings Interface IS

Pluggable, Meaning That You Can Define How Your Settings Are Saved by Implementing Theese Event Routines.

YOU GET The Same Strong Typing with Resources You Add to Your Project. If you drop an image named happy.bmp on Theimages Area of ​​The

Resources designer, you can refer to it in code as My.Resources.Happy. Happy is of type Bitmap, which means that you do not have to cast from an Object or Image type to use the bitmap in code. IntelliSense also works immediately When You Type Happy in your code. for example:

Picturebox1.image =

My.Resources.happy

This Line of Code Assigns The Bitmap Object To a PictureBox's

Image Property. You can see The IntelliSense Pop-Up Window In Figure 4, Indicating That The Object IS of Type Bitmap.

Figure 4. Dragging-Dropping A Bitmap Image on The Resources Tab in The Application Designer Results in a strongly type ibject try...............

As you add forms and web services to your project, the

MY Object Is Dynamically Populated with strongly type in.................

As you can see, My makes it more convenient to find application and environment related BCL classes, and gives you immediate and strongly typed access to settings, resources, and other objects you add to your projects. These are great productivity enhancements for Visual Basic developers Of annuity level.

转载请注明原文地址:https://www.9cbs.com/read-78752.html

New Post(0)