How to get MessageBox.Show() to pop up in the middle of my WPF application?

前端 未结 6 1457
忘掉有多难
忘掉有多难 2020-12-17 08:39

I have a 700w x 300h WPF applciation and can drag it anywhere on my large screen.

When my application executes:

MessageBox.Show(\"Sorry, this functio         


        
6条回答
  •  悲哀的现实
    2020-12-17 09:36

    In addition to Framnk's answer

    This part doesn't work on multiple screens

    ptStart.X = (ptStart.X < 0) ? 0 : ptStart.X;
    ptStart.Y = (ptStart.Y < 0) ? 0 : ptStart.Y;
    

    here's a quickfix:

    var allScreens = System.Windows.Forms.Screen.AllScreens;
    ptStart.X = allScreens.All(a => a.WorkingArea.Left > ptStart.X) ? allScreens.Min(a => a.WorkingArea.Left) : ptStart.X;
    ptStart.X = allScreens.All(a => a.WorkingArea.Right - width < ptStart.X) ? allScreens.Max(a => a.WorkingArea.Right) - width : ptStart.X;
    ptStart.Y = allScreens.All(a => a.WorkingArea.Top > ptStart.Y) ? allScreens.Min(a => a.WorkingArea.Top) : ptStart.Y;
    ptStart.Y = allScreens.All(a => a.WorkingArea.Bottom - height < ptStart.Y) ? allScreens.Max(a => a.WorkingArea.Bottom) - height : ptStart.Y;
    

提交回复
热议问题