共用方式為


IVsLanguageTextOps.Format Method

Formats the selected text.

Namespace:  Microsoft.VisualStudio.TextManager.Interop
Assembly:  Microsoft.VisualStudio.TextManager.Interop (in Microsoft.VisualStudio.TextManager.Interop.dll)

Syntax

'宣告
Function Format ( _
    pTextLayer As IVsTextLayer, _
    ptsSel As TextSpan() _
) As Integer
int Format(
    IVsTextLayer pTextLayer,
    TextSpan[] ptsSel
)
int Format(
    [InAttribute] IVsTextLayer^ pTextLayer, 
    [InAttribute] array<TextSpan>^ ptsSel
)
abstract Format : 
        pTextLayer:IVsTextLayer * 
        ptsSel:TextSpan[] -> int 
function Format(
    pTextLayer : IVsTextLayer, 
    ptsSel : TextSpan[]
) : int

Parameters

Return Value

Type: System.Int32
If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

COM Signature

From textmgr.idl:

HRESULT IVsLanguageTextOps::Format(
   [in] IVsTextLayer *pTextLayer,
   [in] const TextSpan *ptsSel
);

This function is called when the user selects Format Document or Format Selection from the Edit -> Advanced menu, and requests that the language service provide formatting for the referenced text span. Formatting typically means to adjusting line indenting, adding spaces after commas, or even moving braces to a new line with proper indentation.

This method can also be called whenever the user types a character that can trigger a reformat (what that character is depends on the language service but typically it is a closing brace or semicolon).

注意

It is strongly recommended that if you implement this method, you wrap all changes made to the document in an IVsCompoundAction object so the user can undo the entire format operation in one action.

.NET Framework Security

See Also

Reference

IVsLanguageTextOps Interface

Microsoft.VisualStudio.TextManager.Interop Namespace