[C#] WinForm Runtime Add Control & AutoScroll
最主要就是 容器.Controls.Add(新的Control) 當然在這之前要先將這個新的控制項的屬性包含位置都設定好 panel2.AutoScroll = false;//先將AutoScroll disable, 避免新增控制項位置出錯 if (this.Height < 600) this.Height += 65; //新增新搜尋單元 SearchUnit newsearchunit = new SearchUnit(); newsearchunit.Location = new Point(searchUnit2.Location.X, newitem_Y); newitem_Y += 65;//下一次新增時的位置 this.panel2.Controls.Add(newsearchunit); panel2.AutoScroll = true; panel2.AutoScrollPosition = new Point(0, 9000);//新增後置底 參考資料: https://support.microsoft.com/en-us/help/319266/how-to-programmatically-add-controls-to-windows-forms-at-run-time-by-u