C# WPF 中設置窗體顯示在其它窗體上的中間位置

//首先在From1窗體界面加載完進行如下設置,使得From1窗體始終在其它窗體的最上面
 			this.Topmost = true;
			 //首先獲取當前窗體的左上角和右下角座標
            Point ptLeftUp = new Point(0, 0);
            Point ptRightDown = new Point(this.ActualWidth, this.ActualHeight);

            //轉換獲取到這個窗口相對於屏幕兩個座標
            ptLeftUp = this.PointToScreen(ptLeftUp);
            ptRightDown = this.PointToScreen(ptRightDown);

            ////獲取窗體在屏幕的實際寬高
            WidthMan = ptRightDown.X - ptLeftUp.X;
            HeightMan = ptRightDown.Y - ptLeftUp.Y;

			this.IsEnabled = false;//設置當前窗體不可操作
			From1 SetTime = new From1();
            WindowStartupLocation = WindowStartupLocation.Manual;
            WidthMan = (this.ActualWidth) / 2 + ptLeftUp.X - (SetTime.Width) /2;
            HeightMan = (this.ActualHeight) / 2 + ptLeftUp.Y-(SetTime.Height)/2;
            //設置窗體在當前窗體的最中間顯示
            SetTime.Left = WidthMan;
            SetTime.Top = HeightMan;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章