Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

messagebox on top of splashscreen

Tags:

c#

I have a messagebox that pops-up when a user can't be loaded (in this case because he don't have a warehouse) while loading there is a splashscreen that shows that the data is being loaded. I tried the TopMost set to true, but yeah the spalshscreen isn't the parent so it don't work, so i tried TopLevel set to true but it didn't do the trick.

So i tried:

MessageBox.Show(Splashscreen.LoadingScreen.ActiveForm, e.Message, "No warehouses", MessageBoxButtons.OK, MessageBoxIcon.Error);

but this is cross thread so I get an: InvalidOperationException So is there another way to set the messagebox on top?

like image 697
Cageman Avatar asked Dec 25 '22 08:12

Cageman


1 Answers

Try this it will show your MessageBox at the top of every window currently open.

MessageBox.Show(this,
        "Your text",
        "Settings Needed",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button1,
        (MessageBoxOptions)0x40000); // this is MB_TOPMOST flag

This will keep the message box on top of every window because we are passing MB_TOPMOST Value to MessageBoxOptions parameter. You can visit this for more information.

like image 60
Syed Farjad Zia Zaidi Avatar answered Dec 27 '22 20:12

Syed Farjad Zia Zaidi