如何在窗体面板中设置滚动条的位置 (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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:08:01  来源:igfitidea点击:

how to set position of scrollbar in windows form panel (C#)

c#winformsradio-buttonscrollbarpanel

提问by malay

I have lots of radiobuttonin a panelwith auto scroll set to true. One of the radiobuttonis checked. I want to make sure that that the checked one should be visible i.e. the vertical scrollbarshould be moved so that the checked radiobuttonis visible.
Is there any way to do it?

我有很多radiobuttonpanel用自动滚屏设置为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_Shownevent).

为了解决这个问题,我panel.ScrollControlIntoView(radioButton)在显示表单之后(即在事件的事件处理程序中form_Shown)添加了上述代码 ( )。

This is working now. But I still don't have the correct explanation for this.

这是现在工作。但对此我仍然没有正确的解释。