2010-07-19 4 views
1

여기에 이상한 점이 있습니다. WinForms 패널에 프로그램 적으로 레이블 및 축소/축소가 가능한 usercontrol이 추가되었습니다. 사용자 정의 컨트롤은 레이블이 들어있는 그룹에 있습니다. 컨트롤의 크기와 수 때문에 스크롤을 지원하도록 패널을 설정했습니다.스크롤링 패널로 인해 컨트롤이 중간 패널 아래쪽에 나타납니다.

지금까지 매우 좋음 :이 문제는 패널이 위에서 아래로 스크롤 될 때 발생합니다. 패널 내에서 컨트롤을 조작하면 상단에 데드 스페이스 (비어 있음)가 생깁니다. 다음

조작이 일어난다 :

제어가 추가, 삭제 또는 리사이즈

"RearrangeControls는()"메소드를 호출한다. 이 메서드는 컨트롤이 조정될 때마다 추가되는 모든 컨트롤 (컨트롤이 서로 옆에 나타나는 것을 방지하기위한 빈 공간)의 높이를 유지하는 정수를 유지합니다.

반복은 그룹을 통해 이루어지며이 사용자 컨트롤의 인스턴스를 통해 반복되어 적절하게 그룹화됩니다.

내 다시 정렬 방법은 아래에 포함되어 있습니다 (I이 explination 말이 희망) : 모든 컨트롤의

private void RearrangeControls() 
    { 
    Console.WriteLine(String.Format("Top of panel: {0}", pnlMain.Top)); 
    this.SuspendLayout(); 
    //sort ranges in to ascending order, this is the primary grouping 
    _lRanges.Sort(CompareStringAscending); 

    //now sort items by alphabetical order, we will filter out groups later so this will not be a problem 
    _lItems.Sort(CompareSelectionDetailViewAscending); 

    int iYPos = 0; 

    //first sort through by 
    foreach (string selectedRange in _lRanges) 
    { 
     int iRangeControlCount = 0; 

     KryptonLabel label = pnlMain.Controls[selectedRange] as KryptonLabel; 
     label.Location = new Point(_iTitleIndent, iYPos); 

     iYPos += label.Height + _iControlSpacing; 

     //now sort views 
     foreach (SelectionDetailView selectionDetailView in _lItems) 
     { 
      if (selectionDetailView.Range == selectedRange) 
      { 
       selectionDetailView.Location = new Point(_iDetailIndent, iYPos); 
       //Console.WriteLine(String.Format("{0} {1} {2}", selectionDetailView.Name, selectionDetailView.Location.X.ToString(), selectionDetailView.Location.Y.ToString())); 
       iYPos += selectionDetailView.Height + _iControlSpacing; 

       iRangeControlCount++; 
      } 
     } 

     //if this is zero, then it meant the last label we aded has no controls associated wiht it. If this is the case we shoudl remove it from the panel 
     if (iRangeControlCount == 0) 
     { 
      iYPos -= label.Height + _iControlSpacing; 
      pnlMain.Controls.Remove(label); 
     } 

     Console.WriteLine(String.Format("Y: {0}", iYPos)); 
    } 

    pnlMain.ScrollControlIntoView(_oSelectedItem); 
    this.ResumeLayout(); 
    } 

는 Y 값을 모두 0에서 시작이 패널 내에서 그래서 그들은 상단에 있어야합니다. 검색 한 적이 있으며이 오류의 원인에 대한 정보를 찾을 수 없었습니다. 아무도이 일이 벌어지고 있다는 것을 알고 있습니까? 나는이 문제에 관해 어떤 조언/조언/조언을 주셔서 감사합니다.

답변

2

문제가 해결되었습니다.

int iYpos = pnlMain.AutoScrollPosition.Y 

다른 사람이 내가 희망이 도움이 같은 probme에 실행하는 경우 :

나는 다음과 같은 사용을 사용하는 데 필요한.

(나는 키보드 앞에서 마침내 콜타페를했다.) -

+0

이것은 매력처럼 작동했다 !!! 다니엘 고마워. – Naren

관련 문제