2014-10-08 39 views
1

我有一個面板屬性AutoScroll = true。 通過動態添加其他控件到面板而不滾動 - 一切正常!使用自動滾動功能將控件添加到面板(c#)

void addControl(){ 
    int top = 13 + (this.Controls.Count * cmdSet.Height); 
    ucCommandSet cmdSet = new ucCommandSet() { Top = top }; 
    this.Controls.Add(cmdSet); 
} 

但是,如果滾動條插入的位置不是TOP [0],那麼控件將被添加得更遠。

我需要在計算中包含哪些屬性?

問候通過@LarsTech raiserle


解決方案:

void addControl(){ 
    int top = 13 + (this.Controls.Count * cmdSet.Height) + this.AutoScrollPosition.Y; 
    ucCommandSet cmdSet = new ucCommandSet() { Top = top }; 
    this.Controls.Add(cmdSet); 
} 
+0

你能解釋一下'ucCommandSet'是什麼?另外,你是什麼意思的TOP [0]? – 2014-10-08 17:19:43

+0

我的意思是,滾動條是在頂部(Scrollvalue = 0) – raiserle 2014-10-08 17:31:55

+0

對不起,ucCommand是一個用戶控件;) – raiserle 2014-10-08 17:38:58

回答

3

我猜你需要補償滾動位置:

{ Top = top + this.AutoScrollPosition.Y }; 

一個FlowLayoutPanel的做這行順便說一下,你。

+0

謝謝。我'搜索滾動條....不是自動.... **** arg ****。大塔克!視爲raiserle – raiserle 2014-10-08 17:33:14