Share via


TextPane2.TryToShow Method

Adjusts the location of the view in the text buffer so that the indicated range of text is shown in the text pane, if possible. You can control where the text displays in the pane.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Syntax

'Declaration
Function TryToShow ( _
    Point As TextPoint, _
    How As vsPaneShowHow, _
    PointOrCount As Object _
) As Boolean
bool TryToShow(
    TextPoint Point,
    vsPaneShowHow How,
    Object PointOrCount
)
bool TryToShow(
    [InAttribute] TextPoint^ Point, 
    [InAttribute] vsPaneShowHow How, 
    [InAttribute] Object^ PointOrCount
)
abstract TryToShow : 
        Point:TextPoint * 
        How:vsPaneShowHow * 
        PointOrCount:Object -> bool
function TryToShow(
    Point : TextPoint, 
    How : vsPaneShowHow, 
    PointOrCount : Object
) : boolean

Parameters

  • PointOrCount
    Type: System.Object

    Optional. A variant representing the end of a range of text to show. If PointOrCount is a number of characters, the characters follow Point. If PointOrCount is a point before Point, then it is at the top of the text pane if How is set to vsPaneShowTop.

    If How is set to vsPaneShowCentered, and the number of lines in the selected text is greater than the height of the pane, then the top line of the selected text is placed at the top of the pane.

Return Value

Type: System.Boolean
true if the text can be displayed; otherwise, false.

Examples

This example opens a text document, displays text in it, and then uses the TryToShow method of TextPane2 to show the window containing the text pane. For more information about how to run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples.

Imports EnvDTE
Imports EnvDTE80
Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    TextPane2TryToShowExample(_applicationObject)
End Sub
Sub TextPane2TryToShowExample(ByVal dte As DTE2)
    Dim objTW As TextWindow
    Dim objPane As TextPane2
    Dim objTextDoc As TextDocument
    Dim objTextPt As TextPoint
    Dim objEP As EditPoint
    Dim objStart As TextPoint
    ' Create a new text document.
    _applicationObject.ItemOperations.NewFile("General\Text File")
    ' Get a handle to the new document and create EditPoint,
    ' TextPoint, and TextPane objects.
    objTextDoc = CType(_applicationObject.ActiveDocument.Object _
     ("TextDocument"), TextDocument)
    objEP = objTextDoc.StartPoint.CreateEditPoint
    objTextPt = objTextDoc.StartPoint
    ' Plug in some text.
    objEP.Insert("A test sentence.")
    objTW = CType(dte.ActiveWindow.Object, TextWindow)
    objPane = CType(objTW.ActivePane, TextPane2)
    MsgBox("The active pane is " & Str(objPane.Height)  _
    & " lines high and " & Str(objPane.Width) & " columns wide.")
    objStart = objPane.StartPoint
    MsgBox("It begins at line " & Str(objStart.Line)  _
    & ", column " & Str(objStart.LineCharOffset) & ".")
    MsgBox("Using TryToShow to center the pane...")
    objPane.TryToShow(objStart, vsPaneShowHow.vsPaneShowCentered)
End Sub
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
public void OnConnection(object application, 
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    TextPane2TryToShowExample(_applicationObject);
}
public void TextPane2TryToShowExample(DTE2 dte)
{
    TextWindow objTW;
    TextPane2 objPane;
    TextDocument objTextDoc;
    TextPoint objTextPt;
    EditPoint2 objEP;
    TextPoint objStart;
    // Create a new text document.
    _applicationObject.ItemOperations.NewFile
(@"General\Text File", "test.txt", Constants.vsViewKindTextView);
    // Get a handle to the text document and create EditPoint2,
    // TextPoint, and TextPane2 objects.
    objTextDoc =(TextDocument)_applicationObject.ActiveDocument.Object
("TextDocument");
    objEP = (EditPoint2)objTextDoc.StartPoint.CreateEditPoint();
    objTextPt = objTextDoc.StartPoint;
    // Plug in some text.
    objEP.Insert("A test sentence.");
    objTW = (TextWindow)_applicationObject.ActiveWindow.Object;
    objPane = (TextPane2)objTW.ActivePane;
    MessageBox.Show("The active pane is " + objPane.Height 
+ " lines high and " + objPane.Width + " columns wide.");
    objStart = objPane.StartPoint;
    MessageBox.Show("It begins at line " + objStart.Line 
+ ", column " + objStart.LineCharOffset + ".");
    MessageBox.Show("Using TryToShow to show the pane as centered...");
    objPane.TryToShow(objStart, vsPaneShowHow.vsPaneShowCentered, 2);
}

.NET Framework Security

See Also

Reference

TextPane2 Interface

EnvDTE80 Namespace