Displaying a MessageBox on top of all forms, setting location and/or color

Viewed 36121

I have two forms and I set one of the forms' TopMost property to true. Somewhere, while the program runs, I show a MessageBox, but since TopMost is set to true, when the MessageBox pops up it shows under the topmost form so I cannot see it.

  1. Is there any way that I make one of my forms always be on top, but when a MessageBox pops up, make the message box show on top of that specific form?

  2. Is it possible to give a location to the MessageBox so that it shows not in the middle but for example low down on the screen?

  3. Let's say that I have an orange colored form can I have a pink colored message box only for that specific application. I mean I am NOT referring to playing the windows color properties. (I don't want all message boxes to be pink.)

7 Answers
https://stackoverflow.com/questions/29326042/show-message-box-in-net-console-application
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox

using System.Runtime.InteropServices;
//...
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr h, string m, string c, uint type);
const uint ICONERROR = 16;
const uint ICONWARNING = 48;
const uint ICONINFORMATION = 64;
const uint MB_TOPMOST = 262144;

//...
MessageBox((IntPtr)0, "Started" + DateTime.Now, "Log", ICONINFORMATION | MB_TOPMOST);
Related