Visual Basic 2005 New Function Reviews - My.computer of MY Namespace

zhaozj2021-02-16  92

My.computer may be the most interesting part in my namespace. This part encapsulates a large number of functions of the system and hardware information. It is more convenient than direct use .NET Framework or Windows API. There are many objects in My.Computer, and we will introduce them separately.

My.computer.audio

The AUDIO object provides the function of playing audio, which can play both WAV and other files, or from audio data flow, that is, you can use it easy to play in the resource file or audio in the resource file or in the database. You can also specify a variety of settings such as background playback or wait end. Combined with My.Resources to use, it is more convenient to end. This is an example of a simple playing WAV file:

My.computer.Audio.Play ("C: C: / DAV", AudioplayMode.BackgroundLoop)

My.computer.clipboard

The Clipboard object provides a function of reading and writing a clipboard in a strong type, making it better than the clipboard inside Windows.Forms. Use the Clipboard object to read and write audio, images, text, and even files in my computer directly from the clipboard. In addition, items upgraded by VB6 will now use the My.Computer.clipboard object to upgrade the previous CLIPBOARD object, which will resolve the defect of VB.NET can't upgrade the original clipboard function. The following example copies the contents of the text box to the clipboard:

My.computer.clipboard.settext (TextBox1.text)

My.computer.clock

The Clock object is a tool for acquiring time, which can directly get the local time, the time of the time zone and the millisecond count starting from the time.

My.computer.filesystem

This is Microsoft Visual Basic Team to pour the most energyful objects in My.Computer, using it to fully improve the complexity of file operations. The FileSystem object provides an easy way of understanding. The method of replication files in the FileSystem object not only needs to specify the target path, but also helps you establish the level in which you don't exist in the target directory. It also provides the function of CopyDirectory, you can copy the entire directory! This is exactly the lack of .NET Framework. At the same time, FileSystem can also provide the functionality of search, subdirectories, or root directory, very considerate. The following example shows how to put files into the recycle bin under the animation demo.

My.computer.FileSystem.deletefile ("c: /mybigfile.big", true, true)

FileSystem objects also provide only one line of code to read text file content, or write the desired content to the text file, now you don't need to use confused streamreader, StreamWriter to read and write files, don't worry Resource release problem. Such as follows:

s = my.computer.filesystem.readallText ("c: /a.txt")

In addition to the MY access, Most of the FileSystem objects can be completed via System.IO.FileSystem class, which seems to be more suitable for developers using C # or C .

My.computer.info

Look at the name, I know, this object's properties are system information. If you want to get the total number of physical memory or virtual memory, the remaining amount, the operating system name, the current user name, the local installed cultural settings, etc., you can easily use the INFO object, which allows you to the system where the application is Meet if you finger.

My.computer.keyboard and my.computer.mouse

Through these two objects, you can quickly get information about the user keyboard, such as uppercase locking, whether the digital keyboard locks are opened, and if there are several buttons, whether or not the roller is equipped. If you want your app to be the most thoughtful user, then this information is less. The following example demonstrates whether the user's mouse left and right key function is exchanged (so you can know that the user is left-handed, so providing more considerate interface, more cool) Dim f as boolean = my.computer.mouse.buttonsswapped

My.computer.name

Don't say more, this is the name entered when the operating system installation is installed.

My.computer.neetwork

This NetWork object fully simplifies the most commonly used network task, just one line of code, you can ping an address or detect if the network is turned on. You can also download or upload files with a line of code. For example, this example has completed a task of downloading a file:

If.computer.neetwork.isavailable kilnloadfile ("http://abc.com/x.zip", _ "c: / down") endiffy.computer.port

Provides a function of opening the native serial port with a line of code, and can also bind an event monitoring of the serial port. Now the serial port programming is simple and simple, no longer requires a MSCOMM control.

My.computer.printers

This Printers object can traverse all printers installed in this unit, and find the default printer. You can start printing by using the same operation as the default printer. Such actions will allow you to think of a convenient and simple print operation in the VB6 era. The following example will print an ellipse on the default printer. When upgrading from a VB6, the original Printer object will automatically upgrade to the related operations in My.Computer.printers, and the upgrade user can be more secure.

My.computer.printers.defaultprinter.drawellipse (_ New Rectanglef (2, 50, 150), 1) My.computer.printers.defaultprinter.print ()

My.computer.registry

This registry object can be more simple than that of Microsoft.Win32 space, and he provides strong type of path support, and it can also read and write the registry very conveniently. The following example is a built-in code snippet demonstrates how to determine if a key value exists.

DIM EXISTS as Boolean = TRUE

DIM path as string = "Software / Microsoft / TestApp / 1.0"

If my.computer.registry.currentuser.opensubKey (path) is nothing thrrs = false

My.computer.screen

The Screen object can get the visual range of the screen, the number of pixels, and the like. It is stronger than VB6's Screen object that it is now supported two displays.

Now we have learned all objects in My.compute, which simplifies most tasks into a line of code, is it very helpful to your daily programming?

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

New Post(0)