Share via


Document.Activate 메서드

현재 항목으로 포커스를 이동합니다.

네임스페이스:  EnvDTE
어셈블리:  EnvDTE(EnvDTE.dll)

구문

‘선언
Sub Activate
void Activate()
void Activate()
abstract Activate : unit -> unit 
function Activate()

설명

Activate를 호출하면 항목을 클릭한 효과가 나타나지만 Click 이벤트는 발생하지 않습니다.

예제

public void CodeExample(DTE2 dte, AddIn addin)
{   
    try
    {   // Before running, create two text files named "TextFile1.txt"
        // and "TextFile2.txt", include them in your solution,
        // and then open them. Notice changes when code executes.
        Document doc, doc2;
        string msg = "";
        string msg2 = "";
        if (dte.Documents.Count > 0)
        {
            doc = dte.Documents.Item("TextFile1.txt");
            // Find specified text.
            if (doc.MarkText("text to find", 0))
            {
                msg += "(1) The text was found!\n"; //MessageBox.Show("The text was found");
                // Delete the bookmark created by MarkText.
                doc.ClearBookmarks();
            }
            if (doc.ReplaceText("text to find", "was replaced by this", 0))
                msg += "(2) It [was replaced by this].\n";
            if (doc.Undo())
                msg += "(3) The ReplaceText method has been undone.\n";
            if (doc.Redo())
                msg += "(4) The ReplaceText method had been redone.\n";
            // This will bring the other document to the foreground.
            doc2 = doc.Collection.Item("TextFile2.txt");
            doc2.Activate();
            // Have these documents been saved?
            foreach (Document dc in dte.Documents)
            {
                if (dc.Saved) msg += dc.Name + " has been saved.\n";
            }
            MessageBox.Show(msg, "Example Output");
            // Access the application object.
            msg2 += doc2.DTE.Name + " is the application object.\n";
            // Show the Guid for the document.
            msg2 += doc2.Kind + " is the Guid for this document.\n";
            // Show the language used to author the code.
            msg2 += doc2.Language + " is the language used in this document.\n";
            // Show the document's name.
            msg2 += doc2.Name + " is the name of this document.\n";
            // Get the projectitem associated with this document.
            msg2 += doc2.ProjectItem.Name + " is the ProjectItem associated with this document.\n";
            // Show the document type.
            msg2 += doc2.Type + " is the type of document.\n";
            foreach (Window win in doc2.Windows)
            {
                msg2 += win.Caption + " is a window.\n";
            }
            MessageBox.Show(msg2, "Example Output");
        }
        else MessageBox.Show("Sample not setup properly.");
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

Document 인터페이스

EnvDTE 네임스페이스

기타 리소스

방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행