How to: Create FileSystemWatcher Component Instances
You create an instance of thecomponent when you want to build file system monitoring into your application. FileSystemWatcher components allow you to connect to directories and watch for specific changes within them, such as the creation of new files, addition of subdirectories, and renaming of files or subdirectories.
You can add an instance of the FileSystemWatcher component to Windows Forms, Web Forms, and component classes. FileSystemWatcher components have no visual user interface. If you add an instance of the FileSystemWatcher component to a visual designer (such as the Windows Forms Designer), the component appears in a small area below the bottom border of the form. This area is known as the component tray and acts as a place to display all of the nonvisual items associated with the form.
Nonvisual classes that inherit fromsupport a visual design surface similar to the component tray, on which your FileSystemWatcher component and other components are arranged. The arrangement of items on this designer is not important, as the interface you see will never be displayed to the application's end users.
There are several ways you can create an instance of the FileSystemWatcher component:
You can drag an instance of the FileSystemWatcher component from the Components tab of the Toolbox to a form or other designer.
You can create an instance of the FileSystemWatcher component in code.
Unlike many of the other components on the Components tab of the Toolbox, FileSystemWatcher components are not represented in Server Explorer, so you cannot create instances of the component from that window.
To create an instance of the FileSystemWatcher component from the Toolbox
Access the Components tab of the Toolbox.
Select the FileSystemWatcher icon and drag it to the designer surface for your form or component.
Configure your component. For more information, see.
To create an instance of the FileSystemWatcher component programmatically
Create an instance of the FileSystemWatcher base class in code. Your code might look like this:
Configure any other necessary properties for your component. For more information, see.