`

解决窗体得到焦点时,滚动条复原问题

 
阅读更多
public partial class Form1 : Form
    {
        int X_Value; // Stores position of Horizontal scroll bar
        int Y_Value; // Stores position of Vertical scroll bar

        public Form1()
        {
            InitializeComponent();
            this.Scroll+=new ScrollEventHandler(form1_Scroll);
        }

        private void form1_Scroll(object sender, ScrollEventArgs e)
        {
            if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
            {
                X_Value = e.NewValue;
            }

            if(e.ScrollOrientation == ScrollOrientation.VerticalScroll)
            {
                Y_Value = e.NewValue;
            }
        }

        private void Form2_Activated(object sender, EventArgs e)
        {
            this.AutoScrollPosition = new Point(X_Value, Y_Value);
        }
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics