在启动程序时显示可滚动面板的开头

时间:2014-04-21 13:49:42

标签: c# winforms panel

我的程序是某种测试。我在面板中保留问题,但是当我运行程序时,它会显示面板的中间位置。如何让它显示面板的开头? enter image description here

private void Form1_Load(object sender, EventArgs e)
        {

            for (int i = 0; i < 10; i++)
            {
                Dictionary<string, bool> answers = new Dictionary<string,bool>();
                for (int j = 0; j < 4; j++)
                {
                    string ans = "Відповідь " + (j+1);
                    bool flag = false;
                    if( i > 5)
                    {
                        if( j == 0 || j == 2)
                        {
                            flag = true;
                        }
                    }else
                        if (j == 0)
                        {
                            flag = true;
                        }
                    answers.Add(ans, flag);
                }
                string q_text = "Питання № " + (i+1);
                this.AddQuestion(q_text, answers);
            }
            panel1.ScrollControlIntoView(panel1.Controls[0]);
        }

2 个答案:

答案 0 :(得分:0)

您可以使用:

  1. ScrollControlIntoView方法:

    panel.ScrollControlIntoView(panel.Controls[0]);
    
  2. 专家组VerticalScroll财产:

    panel.VerticalScroll.Value = 0;
    

答案 1 :(得分:0)

尝试将焦点设置在Form_Load事件面板中的第一个控件上:

panel1.Controls[0].Select();