如何在窗体面板中设置滚动条的位置 (C#)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1138087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to set position of scrollbar in windows form panel (C#)
提问by malay
I have lots of radiobutton
in a panel
with auto scroll set to true
. One of the radiobutton
is checked. I want to make sure that that the checked one should be visible i.e. the vertical scrollbar
should be moved so that the checked radiobutton
is visible.
Is there any way to do it?
我有很多radiobutton
在panel
用自动滚屏设置为true
。其中之一radiobutton
被检查。我想确保被选中的那个应该是可见的,即垂直scrollbar
应该被移动,以便被选中的人 radiobutton
是可见的。
有什么办法吗?
P.S. I have tried as bellow but it is not working
PS我试过如下,但它不工作
RadioButton radiobutton = new RadioButton();
.....
panel.Controls.Add(radioButton);
if (some logic)
{
radioButton.Checked = true;
panel.ScrollControlIntoView(radioButton);
}
采纳答案by malay
To fix this, I add the above mentioned code (panel.ScrollControlIntoView(radioButton)
) after the form is shown (i.e. in the event handler for form_Shown
event).
为了解决这个问题,我panel.ScrollControlIntoView(radioButton)
在显示表单之后(即在事件的事件处理程序中form_Shown
)添加了上述代码 ( )。
This is working now. But I still don't have the correct explanation for this.
这是现在工作。但对此我仍然没有正确的解释。