IVsTextView Interface


Manages the text view of an editor window and contains methods to manage the text view. The view is essentially the editor window shown in the user interface (UI).

public interface class IVsTextView
public interface class IVsTextView
__interface IVsTextView
public interface IVsTextView
public interface IVsTextView
type IVsTextView = interface
type IVsTextView = interface
Public Interface IVsTextView


The IVsTextView interface is not the MDI child, but an individual window of text. If a splitter is involved, there can be multiple views in an MDI child. The term, caret, refers to the text insertion point, while the term, cursor, refers to the mouse pointer.


This interface is not thread-safe. You should not call anything on this interface from anything but the main UI thread.

If you need to perform any operations on the view from a different thread, you may either:

Some methods on IVsTextViewuse ViewCol coordinates (for example, GetTextStream and GetCaretPos), while others use CharIndex coordinates (for example, GetWordExtent). ViewCol coordinates may include virtual space while CharIndex coordinates are only an offset into a buffer line and never include virtual space.

If you get a coordinate in ViewCol coordinates, then you should only call methods that take CharIndex coordinates after making sure that the ViewCol coordinate does not lie in the virtual space region. For example, if you call the following:

long iLine;

long cCount;

ViewCol iCol;

IVsTextView::SomeMethod(&iLine, &icol);

Then you must check to be sure that the following is true:

IVsTextBuffer::GetLengthOfLine(iLine, &cCount);

iCol < cCount

Then call the following:

IVsTextView::SomeOtherMethod(ViewCol(iCol ))

// where SomeOtherMethod takes ViewCol coordinates

See illustrations of the implementation and/or calling of this interface in the sample Figures Language Service.

Notes to Callers

Called by clients who want to manage their view.


AddCommandFilter(IOleCommandTarget, IOleCommandTarget)

Adds a command filter to the existing chain of command filters.

CenterColumns(Int32, Int32, Int32)

Places the specified column of text in the center of the view.

CenterLines(Int32, Int32)

Places the specified lines of text in the center of the view.


Clears the current selection.


Closes and unregisters a view with the view manager.


Ensures that text is in view, both vertically and horizontally.


Returns the current contents of the text buffer.

GetCaretPos(Int32, Int32)

Returns the line and column index of the cursor position.

GetLineAndColumn(Int32, Int32, Int32)

Converts a text stream position to a line and column index.


Returns the pixel height of a line.

GetNearestPosition(Int32, Int32, Int32, Int32)

Converts a line and column index to a text stream position.

GetPointOfLineColumn(Int32, Int32, POINT[])

Returns the coordinates for the upper left corner of a particular line and column.

GetScrollInfo(Int32, Int32, Int32, Int32, Int32)

Returns the core text editor's scroll bar settings for the specified scroll bar.


Returns a copy of the selected text.

GetSelection(Int32, Int32, Int32, Int32)

Returns the text span corresponding to the current selection, if there is one.


Returns a copy of the selected text in IDataObject interface format.


Returns the current selection mode.


Returns the text span associated with a selection.

GetTextStream(Int32, Int32, Int32, Int32, String)

Returns a specified stream of text in a string.


Returns the window handle for this view.

GetWordExtent(Int32, Int32, UInt32, TextSpan[])

Returns the current word extent.

HighlightMatchingBrace(UInt32, UInt32, TextSpan[])

Highlights the matching brace in a language construct.

Initialize(IVsTextLines, IntPtr, UInt32, INITVIEW[])

Creates the view and allows clients to specify one or more TextViewInitFlags options.

PositionCaretForEditing(Int32, Int32)

Puts the caret in a position suitable for editing a function.


Removes a command filter from the chain of command filters.

ReplaceTextOnLine(Int32, Int32, Int32, String, Int32)

Replaces line text.

RestrictViewRange(Int32, Int32, IVsViewRangeClient)

Reduces the view’s range of visible/editable lines to a subset of the buffer’s lines.


Sends explicit focus to the window.


Associates a text buffer with the view.

SetCaretPos(Int32, Int32)

Sets the coordinates of the end point of a selection.

SetScrollPosition(Int32, Int32)

Sets the core text editor's scroll bar settings for the specified scroll bar.

SetSelection(Int32, Int32, Int32, Int32)

Selects specified text.


Sets the selection mode.


Sets the top line in the view to the baseline.

UpdateCompletionStatus(IVsCompletionSet, UInt32)

Used for word completion control.

UpdateTipWindow(IVsTipWindow, UInt32)

Updates the tip window.


Forces the view to update its frame window caption, such as "[Read only]".

Applies to