admin管理员组文章数量:1297082
I'm programmatically generate a TabPage which contains a Panel with various, also programmatically generated controls. The Panel fits it's size to the included controls and can grow larger than the parent TabPage.
I used TabPage.AutoScroll=true;
to enable scrolling. The Controls inside the Panel are programmatically generated and receive events, therefore they update their values automatically. That causes the TabPage to scroll to the last updated Control into view.
How can I deactivate this automatic scrolling to the updated Control without disabling the user to scroll inside the TabPage manually?
I'm programmatically generate a TabPage which contains a Panel with various, also programmatically generated controls. The Panel fits it's size to the included controls and can grow larger than the parent TabPage.
I used TabPage.AutoScroll=true;
to enable scrolling. The Controls inside the Panel are programmatically generated and receive events, therefore they update their values automatically. That causes the TabPage to scroll to the last updated Control into view.
How can I deactivate this automatic scrolling to the updated Control without disabling the user to scroll inside the TabPage manually?
Share Improve this question edited Mar 5 at 14:31 Poul Bak 10.9k5 gold badges38 silver badges69 bronze badges asked Feb 12 at 10:57 Me.MyBaseMe.MyBase 253 bronze badges 5- 1 Have you verified what is the TabIndex sequence in those Controls? See the notes here: Why does my FlowLayoutPanel automatically scroll back to the top when the form loses and regains focus? – Jimi Commented Feb 12 at 11:33
- 1 Set the page's ActiveControl property to a control that's near the top-left of the page. Typically the first. – Hans Passant Commented Feb 12 at 13:15
- @jimi; I tried that, but that's not the problem. The autoscroll even triggers, if I don't switch the focus anywhere else. the programmatically updated Controls are a label inside of a UserControl which is again nested into another UserControl (which has a ToolStripLabel which is updated as well) whis is part of the Panel inside the TabPage. – Me.MyBase Commented Feb 14 at 10:32
- It's not about focus change, it's about the Control that becomes active when the TabPage is presented. Usually, a Control becomes the ActiveControl in a container if its TabIndex is lower than the other Controls in the same container. But you can set the ActiveControl explicitly, as shown in that Q&A. A ScrollableControl (as the Panel - a TabPage is also a Panel) always scrolls to a point where the ActiveControl is visible – Jimi Commented Feb 14 at 12:58
- @Jimi: sor,y I needed a while to figure it out. that solution was right, yet not as simple as I thought. Because of all those nested controls I hat to set 'this.ParentForm.ActiveControl = this.Parent.Parent.Parent'. Pointing to the Panel mentioned, caused a scroll to the top every second. Pointing to the hosting TabControl fixed the issue. Thanks. :) – Me.MyBase Commented Mar 5 at 11:11
2 Answers
Reset to default 1The solution was to set the Forms ActiveControl Property to a host-control inside the borders of the form.
this.ParentForm.ActiveControl = this.Parent.Parent.Parent.Parent;
- Parent: Panel of the hosting UserControl
- Parent: hosting UserControl
- Parent: Panel of the TabControl
- Parent: TabControl
Have you tried the event
tabControl1.Selecting
You can detect the tab change before it happens with a handler to cancel. Here you can check if the event was initiated by the user or not and cancel the tab change accordingly.
本文标签: winformsC Scrollable TabPage without autoscrollingStack Overflow
版权声明:本文标题:winforms - C# Scrollable TabPage without auto-scrolling - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741606458a2388004.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论