EditorPartCollection.IndexOf(EditorPart) 메서드

정의

컬렉션의 특정 멤버 위치를 반환합니다.

public:
 int IndexOf(System::Web::UI::WebControls::WebParts::EditorPart ^ editorPart);
public int IndexOf (System.Web.UI.WebControls.WebParts.EditorPart editorPart);
member this.IndexOf : System.Web.UI.WebControls.WebParts.EditorPart -> int
Public Function IndexOf (editorPart As EditorPart) As Integer

매개 변수

editorPart
EditorPart

컬렉션의 멤버인 EditorPart입니다.

반환

Int32

컬렉션에 있는 EditorPart 컨트롤의 인덱스에 해당하는 정수입니다.

예제

다음 코드 예제에서는 메서드를 사용 하 여 IndexOf 개체에서 EditorPartCollection 컨트롤을 EditorPart 찾는 방법을 보여 줍니다. 예제를 실행 하는 데 필요한 전체 코드의 예제 섹션을 참조 하세요.를 EditorPartCollection 클래스 개요입니다.

이벤트의 코드 Button1_Click 는 개체를 EditorPartCollection 만든 다음 메서드를 IndexOf 사용하여 컬렉션에서 컨트롤을 PropertyGridEditorPart1 찾고 해당 ChromeType 속성을 설정합니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
  {
    ArrayList list = new ArrayList(2);
    list.Add(AppearanceEditorPart1);
    list.Add(PropertyGridEditorPart1);
    // Pass an ICollection object to the constructor.
    EditorPartCollection myParts = new EditorPartCollection(list);
    foreach (EditorPart editor in myParts)
    {
      editor.BackColor = System.Drawing.Color.LightBlue;
      editor.Description = "My " + editor.DisplayTitle + " editor.";
    }

    // Use the IndexOf property to locate an EditorPart control.
    int propertyGridPart = myParts.IndexOf(PropertyGridEditorPart1);
    myParts[propertyGridPart].ChromeType = PartChromeType.TitleOnly;

    // Use the Contains method to see if an EditorPart exists.
    if(!myParts.Contains(LayoutEditorPart1))
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow;
    
    // Use the CopyTo method to create an array of EditorParts.
    EditorPart[] partArray = new EditorPart[3];
    partArray[0] = LayoutEditorPart1;
    myParts.CopyTo(partArray,1);
    Label1.Text = "<h3>EditorParts in Custom Array</h3>";
    foreach (EditorPart ePart in partArray)
    {
      Label1.Text += ePart.Title + "<br />";
    }

  }

</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)
    
    Dim list As New ArrayList(2)
    list.Add(AppearanceEditorPart1)
    list.Add(PropertyGridEditorPart1)
    ' Pass an ICollection object to the constructor.
    Dim myParts As New EditorPartCollection(list)
    Dim editor As EditorPart
    For Each editor In myParts
      editor.BackColor = System.Drawing.Color.LightBlue
      editor.Description = "My " + editor.DisplayTitle + " editor."
    Next editor
    
    ' Use the IndexOf property to locate an EditorPart control.
    Dim propertyGridPart As Integer = _
      myParts.IndexOf(PropertyGridEditorPart1)
    myParts(propertyGridPart).ChromeType = PartChromeType.TitleOnly
    
    ' Use the Contains method to see if an EditorPart exists.
    If Not myParts.Contains(LayoutEditorPart1) Then
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow
    End If
    
    ' Use the CopyTo method to create an array of EditorParts.
    Dim partArray(2) As EditorPart
    partArray(0) = LayoutEditorPart1
    myParts.CopyTo(partArray, 1)
    Label1.Text = "<h3>EditorParts in Custom Array</h3>"
    Dim ePart As EditorPart
    For Each ePart In partArray
      Label1.Text += ePart.Title + "<br />"
    Next ePart

  End Sub

</script>

브라우저에서 페이지를 로드할 때 표시 모드 드롭다운 목록 컨트롤에서 편집 을 선택하여 페이지를 편집 모드 로 전환할 수 있습니다. 컨트롤의 제목 표시 TextDisplayWebPart 줄에서 동사 메뉴(아래쪽 화살표)를 클릭하고 편집 을 클릭하여 컨트롤을 편집할 수 있습니다. 편집 UI(사용자 인터페이스)가 표시되면 모든 컨트롤을 EditorPart 볼 수 있습니다. EditorPartCollection 만들기 단추를 클릭하면 페이지 아래쪽에 있는 컨트롤에 제목이 있지만 테두리는 없음을 알 PropertyGridEditorPart1 수 있습니다.

설명

IndexOf 메서드는 웹 파트 페이지에 여러 EditorPart 컨트롤이 있고 컬렉션에서 특정 컨트롤을 찾아야 하는 경우에 유용합니다.

적용 대상

추가 정보