Share via


옵션 설정 제어

업데이트: 2007년 11월

도구 메뉴의 옵션 대화 상자에서 여러 가지 페이지(이하 "옵션 페이지")의 설정을 활성화하거나 비활성화할 수 있습니다. Visual Studio 자동화 모델에서 DTE 개체의 Item 메서드와 PropertiesValue 속성을 사용하기만 하면 됩니다.

참고:

일부 옵션 페이지의 몇몇 항목에는 프로그래밍 방식으로 액세스할 수 없습니다. 작업 목록 옵션 페이지의 주석 토큰 목록 같은 대부분의 항목은 프로그래밍 방식으로 보거나 변경할 수 있습니다. 그러나 환경 페이지의 도움말 노드에 있는 동적 도움말 페이지 같은 일부 옵션 페이지는 프로그래밍 방식으로 보거나 변경할 수 없습니다. 또한 일부 옵션 페이지의 설정은 프로그래밍할 수 있지만 일부 페이지 항목에는 반드시 액세스할 필요가 없습니다. 설정을 변경할 수 없는 경우에는 VSIP(Visual Studio Industry Partner) 프로그램을 사용해야 할 수도 있습니다. 자세한 내용은 이 항목의 뒷부분에 있는 "기존 옵션 페이지에 설정 추가" 단원을 참조하십시오. 프로그래밍 방식으로 액세스할 수 있는 옵션과 각 옵션의 정확한 이름에 대한 전체 목록은 옵션 페이지에서 속성 항목의 이름 확인에서 "속성 항목 이름"을 참조하십시오.

옵션 설정 표시

기존 옵션 페이지의 설정에 액세스하려면 Properties 컬렉션과 Property 개체를 사용합니다. 다음 VSMacro 예제에서는 문서 옵션 페이지의 모든 항목에 대한 전체 이름과 현재 값을 표시합니다.

' Macro code.
Sub PropertiesExample()
    ' Create and initialize a variable to represent the Documents 
    ' Options page.
    Dim envGenTab As EnvDTE.Properties = _
    DTE.Properties("Environment", "Documents")
    Dim prop As EnvDTE.Property
    Dim msg As String

    ' Loop through each item in the Documents Options box.
    For Each prop In envGenTab
        msg += ("PROP NAME: " & prop.Name & "   VALUE: " & _
        prop.Value) & vbCr
    Next
    MsgBox(msg)
End Sub

다음 VSMacro 예제에서는 환경 노드 아래의 작업 목록에 대한 옵션 페이지에 사용할 수 있는 모든 속성을 표시합니다. 이 예제에서는 주석 토큰 목록에 사용할 수 있는 모든 값도 나열합니다.

' Macro code.
Sub DisplayProperties()
    ' Variables to represent the properties collection
    ' and each property in the Options dialog box.
    Dim prop As EnvDTE.Property
    Dim props As EnvDTE.Properties
    Dim propVals As Object()
    Dim propVal, msg As String

    ' Represents the Task List Node under the 
    ' Enviroment node.
    props = DTE.Properties("Environment", "TaskList")
    ' Represents the items in the comment Token list
    ' and their priorities (1-3/low-high).
    prop = props.Item("CommentTokens")
    propVals = prop.Value

    Try
        ' List each property name for the Options page
        ' and all of its possible values.
        For Each prop In props
            msg += "PROP NAME: " & prop.Name & vbCr
            For Each propVal In propVals
                msg += "  Value: " & propVal & vbCr
            Next
        Next
        MsgBox(msg)
    Catch ex As System.Exception
        MsgBox("ERROR: " & ex.Message)
    End Try
End Sub

이 예제에서는 텍스트 편집기 | C# | 서식 아래의 옵션 페이지의 프로그래밍 가능한 모든 설정을 나열합니다.

' Macro code.
Sub PropertiesExample()
    ' Create and initialize a variable to represent the C# 
    ' Formatting text editor options page.
    Dim txtEdCSFormat As EnvDTE.Properties = _
    DTE.Properties("TextEditor", "CSharp - Formatting")
    Dim prop As EnvDTE.Property
    Dim msg As String

    ' Loop through each item in the C# Formatting Options page.
    For Each prop In txtEdCSFormat
        msg += ("PROP NAME: " & prop.Name & "   VALUE: " & _
        prop.Value) & vbCr
    Next
    MsgBox(msg)
End Sub

옵션 설정 변경

기존 옵션 페이지에 있는 컨트롤의 값을 변경할 수는 있지만 컨트롤이나 설정을 추가, 제거 또는 수정할 수는 없습니다. 자신만의 설정을 지정하려면 사용자 지정 옵션 페이지를 만들어야 합니다. 자세한 내용은 방법: 사용자 지정 도구 옵션 페이지 만들기를 참조하십시오.

옵션 페이지에서 항목의 값을 변경하는 작업은 값을 표시하는 작업과 매우 비슷합니다. 다음 매크로 예제에서는 그 방법을 설명합니다.

첫 번째 예제(ToolOpt1)에서는 ReuseSavedActiveDocWindow의 부울 값에 대해 설정/해제를 전환합니다. 이는 환경 노드의 문서 페이지에 있는 "저장되면 현재 문서 창 다시 사용" 옵션에 해당합니다.

' Macro code.
Sub ToolOpt1()
    Dim props As EnvDTE.Properties = DTE.Properties("Environment", _
    "Documents")
    Dim prop As EnvDTE.Property

    prop = props.Item("ReuseSavedActiveDocWindow")
    ' If value is TRUE, change it to FALSE, or vice-versa.
    MsgBox("PROP NAME: " & prop.Name & "   VALUE: " & prop.Value)
    prop.Value = Not (prop.Value)
    MsgBox("PROP NAME: " & prop.Name & "   VALUE: " & prop.Value)
    ' Change it to the original value.
    prop.Value = Not (prop.Value)
End Sub

다음 VSMacro 예제에서는 텍스트 편집기 노드의 기본 페이지에 있는 탭 섹션에서 탭 크기 값을 변경한 다음 다시 설정합니다.

' Macro code.
Sub ToolOpt2()
    Dim props As EnvDTE.Properties = DTE.Properties("TextEditor", _
    "Basic")
    Dim prop As EnvDTE.Property
    Dim tmp As String

    prop = props.Item("TabSize")
    ' Set a new value for Tab Size.
    MsgBox("PROP NAME: " & prop.Name & "   VALUE: " & prop.Value)
    tmp = prop.Value
    prop.Value = 10
    MsgBox("PROP NAME: " & prop.Name & "   VALUE: " & prop.Value)
    ' Change it back to the original value.
    prop.Value = tmp
    MsgBox("PROP NAME: " & prop.Name & "   VALUE: " & prop.Value)
End Sub

이 VSMacro 예제에서는 환경 노드의 글꼴 및 색 페이지에 있는 설정을 변경합니다.

' Macro code.
Sub ToolOpt3()
    ' Changes the background color of text in the Fonts and Colors
    ' page of the Options dialog box on the Tools menu.
    Dim props As EnvDTE.Properties
    Dim prop As EnvDTE.Property
    Dim fontColorItems As EnvDTE.FontsAndColorsItems

    props = DTE.Properties("FontsAndColors", "TextEditor")
    prop = props.Item("FontsAndColorsItems")
    fontColorItems = prop.Object

    Try
        MsgBox("NAME: " & prop.Name & vbCr & "BACKGROUND VALUE: " & _
        CStr(fontColorItems.Item("Plain Text").Background.ToString))
        ' Turn the text background from its current color to red.
        fontColorItems.Item("Plain Text").Background = 255
        MsgBox("NAME: " & prop.Name & vbCr & "BACKGROUND VALUE: " & _
        Hex(fontColorItems.Item("Plain Text").Background.ToString))
    Catch ex As System.Exception
        MsgBox("ERROR: " & ex.Message)
    End Try
End Sub

이 VSMacro 예제에서는 옵션 대화 상자의 텍스트 편집기 노드에서 여러 가지 언어에 대한 줄 번호 매기기를 설정합니다.

' Macro code.
Sub TurnOnLineNumbers()
   DTE.Properties("TextEditor", "Basic").Item("ShowLineNumbers") _
   .Value = True
   DTE.Properties("TextEditor", "PlainText").Item("ShowLineNumbers") _
   .Value = True
   DTE.Properties("TextEditor", "CSharp").Item("ShowLineNumbers") _
   .Value = True
   DTE.Properties("TextEditor", "HTML/XML").Item("ShowLineNumbers") _
   .Value = True
   DTE.Properties("TextEditor", "C/C++").Item("ShowLineNumbers") _
   .Value = True
   DTE.Properties("TextEditor", "Visual JSharp") _
   .Item("ShowLineNumbers").Value = True
End Sub

기존 옵션 페이지에 설정 추가

글꼴 및 색 페이지에 자신만의 글꼴 설정을 추가하는 경우와 같이 기존 옵션 페이지에 고유한 설정을 추가하거나 기존 설정을 변경해야 하는 경우가 생길 수 있습니다. Visual Studio 자동화 모델로는 이 작업을 수행할 수 없습니다. VSIP(Visual Studio Industry Partner) 프로그램을 사용해야 합니다. 자세한 내용은 Visual Studio Industry Partner 웹 사이트를 참조하십시오.

참고 항목

작업

방법: 사용자 지정 도구 옵션 페이지 만들기

방법: 창 특성 변경

방법: 추가 기능 만들기

연습: 마법사 만들기

개념

자동화 개체 모델 차트

기타 리소스

환경 창 만들기 및 제어

추가 기능 및 마법사 만들기

자동화 및 확장성 참조