两个winform窗体同步

时间:2023-12-29 22:37:56

/// <summary>
        /// 初始left距离
        /// </summary>
        int initx = 0;
        /// <summary>
        /// 初始top距离
        /// </summary>
        int inity = 0;
        /// <summary>
        /// 初始left距离
        /// </summary>
        int initx1 = 0;
        /// <summary>
        /// 初始top距离
        /// </summary>
        int inity1 = 0;

/// <summary>
        /// 界面初始化
        /// </summary>
        public WriteForm()
        {
            InitializeComponent();
            initx = this.Left;
            inity = this.Top;
            initx1 = form2.Left;
            inity1 = form2.Top;
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }

private void WriteForm_Move(object sender, EventArgs e)
        {
            form2.Top = initx1 + (this.Top - inity);
            form2.Left = inity1 + (this.Left - initx) - this.form2.Width;
        }