Partager via


Changing View Settings by Using the Legacy API

Settings for core editor features, such as word wrap, selection margin, and virtual space, can be changed by the user by means of the Options dialog box. However, it is also possible to change these settings programmatically.

Changing Settings by Using the Legacy API

The IVsTextEditorPropertyCategoryContainer interface exposes a set of text editor properties. The text view contains a category of properties (GUID_EditPropCategory_View_MasterSettings) that represents the group of programmatically changed settings for the text view. Once view settings have been changed in this way, they cannot be changed in the Options dialog box until they are reset.

Following is the typical process for changing view settings for an instance of the core editor.

  1. Call QueryInterface on the (VsTextView) for the IVsTextEditorPropertyCategoryContainer interface.

  2. Call the GetPropertyCategory method, specifying a value of GUID_EditPropCategory_View_MasterSettings for the rguidCategory parameter.

    Doing this returns a pointer to the IVsTextEditorPropertyCategoryContainer interface, which contains the set of forced properties for the view. Any settings in this group are permanently forced. If a setting is not in this group, then it will follow the options specified in the Options dialog box or the user's commands.

  3. Call the SetProperty method, specifying the appropriate settings value in the idprop parameter.

    For example, to force word wrap, call SetProperty and specify a value of VSEDITPROPID_ViewLangOpt_WordWrap, vt for the idprop parameter. In this call, vt is a VARIANT of type VT_BOOL and vt.boolVal is VARIANT_TRUE.

Resetting Changed View Settings

To reset any changed view setting for an instance of the core editor, call the RemoveProperty method and specify the appropriate setting value in the idprop parameter.

For example, to allow word wrap to float freely, you would remove it from the property category by calling RemoveProperty and specifying a value of VSEDITPROPID_ViewLangOpt_WordWrap for the idprop parameter.

To remove all changed settings for the core editor at once, specify a value of VSEDITPROPID_ViewComposite_AllCodeWindowDefaults, vt for the idprop parameter. In this call, vt is a VARIANT of type VT_BOOL and vt.boolVal is VARIANT_TRUE.

See Also

Reference

Options Dialog Box (Visual Studio)

Concepts

Accessing theText View by Using the Legacy API

Other Resources

Inside the Core Editor