Simple logging dockable window with a custom context menu


Purpose
This sample shows how to create a custom dockable window for use in ArcGIS Desktop applications. A dockable window is a window that can exist in a floating state or be attached to the main application window. The table of contents in ArcMap is an example of a dockable window.
 
Use the IDockableWindowDef interface to define a custom dockable window to be created by the application. This interface allows you to set properties and define what the child control window consists of. The class you create is the definition of the window, not the actual dockable window object you interact with in the application. The application uses the definition of the dockable window in your class to create the actual dockable window, accessed by the IDockableWindow interface. You can query properties of the dockable window, such as caption, name, and visibility, as well as user-defined data.
 
The dockable window in this sample contains a list box for message logging, and the list box is exposed to other components via the IDockableWindowDef.UserData property. Other components can access the list box by the IDockableWindow.UserData property. A command that toggles the visibility of the dockable window is also included.
 
This sample also demonstrates different ways to provide a custom context menu that manipulates message items in the list box of the custom dockable window. You can either use the pure .NET Windows Forms ContextMenuStrip class or an ArcGIS framework context menu to implement the context menu. In general, the ContextMenuStrip class is less complicated to implement since the context menu code can be contained in the same class as the dockable window. However, it has a slightly different look and feel than the standard ArcGIS context menu and cannot be interactively customized with the Customize dialog box.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Open and compile the sample project in Visual Studio. If needed, set up a debug application.
  2. Open ArcCatalog, ArcMap, ArcScene, or ArcGlobe. Drag and drop the Show/Hide Log Window (VB .NET) or Show/Hide Log Window (C#) toggle command from the Customize dialog box under the .NET Samples category onto the application.
  3. Click the command to show the dockable window.
  4. Dock the window at various locations on the application window.
  5. Float the dockable window.
  6. Insert text into the list box by typing in the text box and press Enter.
  7. In the Context Menu Option panel at the bottom of the dockable window, select the Pure .NET (Windows Forms) radio button and right-click the list box. A context menu from the Windows Forms ContextMenuStrip class is displayed.
  8. Switch to the predefined (ArcObjects) option and right-click the list box again. A standard ArcGIS Desktop context menu is displayed.
  9. This predefined context menu can be customized interactively in the Customize dialog box. Click the Toolbars tab, check Context Menu and expand to show Logging Window Context Menu (VB .NET) or Logging Window Context Menu (C#). Reverse the order of the commands. After closing the dialog box, right-click the list box again to see your interactive change.
  10. Switch to the Dynamic (ArcObjects) option and right-click the list box. It displays a similar ArcGIS Desktop context menu that is created dynamically at run time that is not customizable.

ClearLoggingCommand.cs Command to clear all items in the logging list box of the dockable window.
LoggingDockableWindow.cs User control with dockable window definition implementation.
LoggingDockableWindowCommand.cs Command toggling visibility of the dockable window.
LoggingWindowCtxMnu.cs Context menu class for the list box of the dockable window.
LogLineMultiItemCmd.cs MultiItem command listing items in the list box of the dockable window.
Download the C# files
ClearLoggingCommand.vb Command to clear all items in the logging list box of the dockable window.
LoggingDockableWindow.vb User control with dockable window definition implementation.
LoggingDockableWindowCommand.vb Command toggling visibility of the dockable window.
LoggingWindowCtxMnu.vb Context menu class for the list box of the dockable window.
LogLineMultiItemCmd.vb MultiItem command listing items in the list box of the dockable window.
Download the VB.NET files

Download the files for all languages




Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo