Managed Basic Editor
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

Managed Basic Editor Sample (C#)

Visual Studio 2005
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

The Managed Basic Editor is a sample VSPackage that demonstrates how to use Visual Studio interop assemblies and the managed package helper classes to create and register a standard file-based rich-text editor.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices.  Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

The following procedures explain the steps involved in building and running a Managed Basic Editor sample.

To build the managed Basic Editor sample

  1. Start Visual Studio and open the BasicEditor.sln file.

  2. On the Build menu, choose Rebuild Solution.

  3. Run the following at the command line to merge command bars and other UI items.

    devenv.exe /setup /rootsuffix exp

    The BasicEditor sample registers itself by invoking the RegPkg tool in a post build event, defined in the Properties dialog box of the BasicEditor project.

To run the managed Basic Editor sample

  1. Start Visual Studio using the experimental build by typing the following at the Visual Studio command line:

    devenv.exe /rootsuffix exp

  2. On the File menu, choose New, and then choose File. Click My Editor, and then Open. A new rich-text-file window with the extension myextFile1 (or 2, 3, or so on) opens.

Once you have built the sample, you can use the following:

  • Save/Save as

  • Find and Replace

  • Copy and Paste

Because the BasicEditor class in VsPkg.cs inherits from the Package class, all of the methods of the IServiceProvider and IVsPackage interfaces and RegisterEditorFactory class are provided by default. The VsPkg.cs includes Package methods for IVsPackage and a declaration of a variable of the EditorFactory type. EditorPane.cs includes a class declaration that inherits from IOleCommandTarget. The following list shows all the interfaces implemented by the Managed Basic Editor sample.

The sample also implements several attribute classes. These classes are made available to RegPkg through reflection, and allow the correct registration of the BasicEditor assembly. For more information on registering packages using RegPkg, see How to: Register Managed VSPackages.

The following table lists the interfaces called by the managed Basic Editor sample and their associated services. Some of the services (IProfferService, for example) are called by the Package class.

The following table lists the important files used when implementing the Managed Basic Editor sample.

Source file Description

Editor.cs

Implementation of myeditor MyEditor that inherits from RichTextBox.

EditorFactory.cs

Implementation of EditorFactory that inherits from IVsEditorFactory.

EditorPane.cs

Implementation of an editor pane. An editor pane hosts the editor and is responsible for handling the commands targeted to the editor as well as saving and loading the document. This program unit also instantiates a SelectionContainer class to allow for the selection or retrieval of IDispatch interface objects to display in the Properties window.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

Robust Programming

The Managed Basic Editor sample demonstrates a simplified embedding approach to a standard editor. In a simplified embedding implementation, the Windows Form is parented to Visual Studio and IVsWindowPane, and IOleCommandTarget is implemented to support handling window commands. ( For more information, see Simplified Embedding.) The Managed Basic Editor sample also demonstrates using an editor factory (that is, IVsEditorFactory) and find-and-replace functionality.

NoteNote

The default location for the Managed Basic Package sample is <drive>:\Program Files\Visual Studio 2005 SDK\<build number>\VisualStudioIntegration\Unsupported\CS_Samples\BasicEditor\BasicEditor. The code for IVsPackage and IOleCommandTarget implementation is located in the VsPkg.cs file.

See Also

Show:
© 2016 Microsoft