TextPane2.TryToShow 方法 (TextPoint, vsPaneShowHow, Object)
如果可能,调整视图在文本缓冲区中的位置,以便在文本窗格中显示指示的文本范围。 您可以控制文本在窗格中的显示位置。
命名空间: EnvDTE80
程序集: EnvDTE80(在 EnvDTE80.dll 中)
语法
声明
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
参数
- Point
类型:EnvDTE.TextPoint
必选。要显示的 TextPoint 位置。
- How
类型:EnvDTE.vsPaneShowHow
必选。一个指示如何显示文本的 vsPaneShowHow 常数。
- PointOrCount
类型:System.Object
可选。一个表示要显示的文本范围的末尾的变量。如果 PointOrCount 是字符数,则这些字符紧跟在 Point 之后。如果 PointOrCount 是在 Point 之前的一个点,则在将 How 设置为 vsPaneShowTop 的情况下,该点就位于文本窗格的顶部。
如果 How 设置为 vsPaneShowCentered 并且选定文本中的行数大于窗格的高度,则选定文本的第一行放置在窗格的顶部。
返回值
类型:System.Boolean
如果文本可以显示,则为 true;否则 false。
实现
TextPane.TryToShow(TextPoint, vsPaneShowHow, Object)
示例
此示例打开一个文本文档,显示其中的文本,然后使用 TextPane2 的 TryToShow 方法显示包含文本窗格的窗口。 有关如何作为外接程序运行此示例的更多信息,请参见 如何:编译和运行自动化对象模型代码示例。
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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。