The Components Toolbox Group


Components are controls that can be dragged into the designer and manipulated at design time but have no actual user interface. These components are used for things like performing tasks in the background, setting up timed events, providing error and help text to other controls on a form, and even things like monitoring the file system, searching Active Directory, storing images, and much more. This section walks you through the "Components" category of the Toolbox and illustrates what the components are and how they should be used.

The BackgroundWorker Component

The BackgroundWorker component facilitates multithreaded programming by providing methods that notify the foreground (the main UI) thread when progress has occurred and has been completed. All you really need to do is define the method that will perform the background task and periodically call ReportProgress from within your background thread, and the complexities previously required of Windows Forms multithreaded programming are all handled.

The DirectoryEntry Component

The DirectoryEntry component is used to represent a single information entry within an LDAP directory source such as Active Directory or ADAM (Active Directory Application Mode).

The DirectorySearcher Component

The DirectorySearcher component provides the ability to search through an LDAP directory source for information and return results in the form of DirectoryEntry lists.

The ErrorProvider Component

As you saw with the ToolTip control, provider-type controls extend existing controls by adding properties to the designer view and allowing you to set those extended properties programmatically at runtime. The ErrorProvider allows your user interface to bring up icons next to input fields that have invalid data in them. You basically tell the provider where the error icon should appear in relation to the control with the error and indicate the error text, as shown in Figure 35.6.

Figure 35.6. The ErrorProvider component in action.


The EventLog Component

The EventLog component provides a componentized wrapper around a specific event log. Using the Log and Source properties, you can indicate which log the component will use and the application name that will be given as the event source. You can use this component to write new entries to the event log or even monitor changes to that event log so that your code can respond when new entries are written to the specified log.

The FileSystemWatcher Component

The FileSystemWatcher is a monitoring component that allows your code to "listen" for specific changes to the file system. For example, you can monitor a directory and respond using an event handler when a new file is added to that directory. Although the FileSystemWatcher is an extremely powerful tool for monitoring disk-level activity, you should not use it when precise timing is required. In order to keep the overhead of this component low, it may not always inform your code immediately when a change occurs. In situations with very high load, it is possible that this component can be several seconds behind the actual activity.

The HelpProvider Component

The HelpProvider control is an extremely useful component that allows you to provide contextual help for individual controls by extending those controls in the same manner as the ToolTip and ErrorProvider controls. With a HelpProvider control present on your form, all controls on the form will have a Help on helpProvider1 (or whatever the name of your help provider is) property that you can use to provide contextual help. You will also see additional properties such as ShowHelp on xx, HelpKeyWord on xx, HelpNavigator on xx, and HelpString on xx where xx is the name of the help provider component. Figure 35.7 shows an example of a simple help provider in action.

Figure 35.7. The HelpProvider component.


Using the Visual Studio 2005 Image Library

One of the most annoying things about previous versions of Visual Studio was that the graphics that came with it were extremely outdated. The library itself hadn't been updated since early on in Visual Basic 6's life, making the icons, bitmaps, and animations provided by Visual Studio .NET completely unusable in a modern application. With Visual Studio 2005, Microsoft has supplied a full library of extremely professional-looking bitmaps, icons, and animations that are current and fit well with Windows XP and Office style guidelines. To get this library, you can extract all of the files from the \Program Files\Microsoft Visual Studio 8\Common7\VS2005ImageLibrary.zip file that ships with Visual Studio 2005. Keep in mind that this file might not show up depending on the options you chose at installation.


The ImageList Component

This component is responsible for storing a list of images. ImageList components are used by other components for supplying a list of images such as the list of icons used in a ListView or a TReeView control. The designer is very easy to use and allows you to browse and preview images contained in the ImageList.

The MessageQueue Component

This component provides an encapsulation around interaction with a specific Microsoft Message Queues (MSMQ) Queue.

The PerformanceCounter Component

This component provides an interface to the Windows Management layer by allowing you access to a performance counter. You can both read existing values from the performance counter or write new ones or even create your own custom counter.

The Process Component

The process component provides access to process-level information and methods concerning a specific process. It is most often used to launch subapplications from within the main application.

The SerialPort Component

The .NET Framework 2.0 is the first version of the framework to have native support for serial communications, making the lives of a lot of developers working with embedded software and hardware developers much happier. This component provides access to a specific serial port, allowing you to read and write data to/from the port as well as respond to port-specific events.

The ServiceController Component

The ServiceController component provides access to a specific Windows Service, allowing you to start and stop that service. You can even control services on other machines provided the infrastructure and security environment supports such actions.

The Timer Component

The Timer component sets up an event that will fire at a specific time interval, allowing your code to execute on that time interval.



Microsoft Visual C# 2005 Unleashed
Microsoft Visual C# 2005 Unleashed
ISBN: 0672327767
EAN: 2147483647
Year: 2004
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net