0

I have a message box to be displayed and I have set it to top most in C#. When the message box is displayed , I want to move it only in the opened application area and not any where else in the desktop. Is it possible ??

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • 1
    Please note that the `visual-studio` tag should only be used for questions about Visual Studio, not code merely written or viewed using it. – ProgrammingLlama Jul 19 '18 at 08:01
  • Possible duplicate of https://stackoverflow.com/questions/29023376/how-to-make-a-dialogview-open-up-on-the-same-monitor-as-the-main-window – Antoine V Jul 19 '18 at 08:06
  • Nope . I am already setting the owner. My question is that once we show the message box , it can be moved anywhere on the screen. I want to limit the movement only till its main application. Is it possible ?? – user2862843 Jul 19 '18 at 08:16
  • I don't think so; even a normal Form when shown as Dialog cannont be restricted in its movement. This code `f2.Move += (ss, ee) => { f2.Left = Math.Min(Math.Max( f2.Left, Left), Right - f2.Width); f2.Top = Math.Min(Math.Max( f2.Top, Top), Bottom - f2.Height); };` simply fails for a form f2 shown with f2.ShowDialog(); usually makes sense as users should be able to look under the dialog.. – TaW Jul 19 '18 at 09:03
  • The only type of application that (normally) has windows restricted to being contained within other windows are [MDI](https://learn.microsoft.com/en-us/dotnet/framework/winforms/advanced/multiple-document-interface-mdi-applications). However, even with those it's normal to *not* constrain dialogs using that mechanism and I would strongly suggest you don't re-architect your whole application just to get this behaviour that'll probably *confuse* your users more than any benefit you expect to gain from it. – Damien_The_Unbeliever Jul 19 '18 at 09:27
  • 1
    https://stackoverflow.com/a/2576220/17034 – Hans Passant Jul 19 '18 at 10:46

0 Answers0