Share via


옵션 설정 제어

옵션 대화 상자(이후 옵션 페이지로 표시)의 페이지에서 여러 설정을 활성화 또는 비활성화하도록 코드를 작성할 수 있습니다. Visual Studio 자동화 모델에서는 Properties 속성, Value 속성 및 DTE 개체의 Item 메서드만 사용하십시오.

참고

많은 옵션 페이지의 여러 항목을 프로그래밍 방식으로 액세스할 수 있지만 특정 페이지에 액세스할 수 없는 항목이 포함될 수 있습니다. 또한 옵션 페이지 자체에 액세스하지 못할 수도 있습니다. 자동화 모델을 사용하여 설정을 변경할 수 없는 경우 Visual Studio SDK를 사용하여 설정을 변경할 수도 있습니다. 자세한 내용은 이 문서의 뒷부분에 있는 "기존 옵션 페이지에 설정 추가"를 참조하십시오. 프로그래밍 방식으로 액세스할 수 있는 옵션 목록과 해당 옵션의 정확한 이름을 보려면 옵션 페이지에서 속성 항목의 이름 확인에서 "속성 항목 이름"을 참조하십시오.

IDE(통합 개발 환경)에서 옵션 대화 상자를 열려면 도구 메뉴에서 옵션을 클릭합니다.

옵션 설정 표시

Properties 컬렉션 및 Property 개체를 사용하여 옵션 페이지의 설정에 액세스합니다. 다음 Visual Studio 매크로 예제에서는 문서 페이지에 있는 항목의 이름, 현재 값 및 형식을 보여 줍니다.

' 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
            Try
                msg += ("PROP NAME: " & prop.Name & _ 
                " VALUE: " & prop.Value) & _
                "   TYPE: " & prop.Value.GetType.ToString()) & vbCr
            Catch
            End Try
    Next
    MsgBox(msg)
End Sub

다음 매크로 예제에서는 작업 목록(환경 노드 아래)에 대한 옵션 페이지에서 제공되는 속성을 보여 줍니다. 이 매크로에는 토큰 목록 주석에 대해 사용 가능한 값도 나열되어 있습니다.

' 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

옵션 설정 변경

옵션 페이지에서 설정 값을 표시할 수 있을 뿐만 아니라 값도 변경할 수 있습니다. 다음 Visual Studio 매크로 예제에서는 이를 수행하는 방법을 보여 줍니다.

참고

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

첫 번째 예제(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

다음 매크로 예제에서는 텍스트 편집기 노드 아래의 기본 페이지의 섹션에 있는 탭 크기 값을 변경하고 재설정합니다.

' 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

이 매크로 예제에서는 환경 노드 아래의 글꼴 및 색 페이지에서 설정을 변경합니다.

' 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

이 매크로 예제에서는 텍스트 편집기 노드에서 여러 언어에 대한 줄 번호 매김 기능을 설정합니다.

' 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 자동화 모델을 사용하여 설정을 기존 옵션 페이지에 추가하거나 기존 설정을 변경할 수 없습니다. 이러한 종류의 항목을 수정하려면 Visual Studio SDK를 사용해야 합니다. 자세한 내용은 Development Tools Ecosystem Partner Portal 웹 사이트를 참조하십시오.

참고 항목

작업

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

방법: 창 특성 변경

방법: 추가 기능 만들기

연습: 마법사 만들기

개념

자동화 개체 모델 차트

기타 리소스

환경 창 만들기 및 제어

추가 기능 및 마법사 만들기

자동화 및 확장성 참조