0

I have a win form containing only progress bar and logic for opening and closing an excel or word document using interopt dll. This win form runs when I click a button in my web application. The problem is, the win form after closing document displays a Message Box. This message box always remains in the taskbar instead of Showing up in the screen.

PS:

DialogResult Result = MessageBox.Show("Save","Confirm", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

When I give the message box in this format, the message box always remains in the taskbar. But the functionalities given as properties for the message box works fine.

DialogResult Result = MessageBox.Show("Save","Confirm", MessageBoxButtons.YesNoCancel,MessageBoxOptions.DefaultDesktopOnly, MessageBoxIcon.Question);

When I give the message box in this format, the message box does not remains in the taskbar but the variable "Result" always returns "No".

Thanks in Advance

  • in which class/thread are you putting above code? – Lei Yang Mar 10 '17 at 07:20
  • I have a created a class in business layer as 'public class WordTemplate' and included the code in it. what do you mean by "which class"? – BalajiKasiraj Mar 10 '17 at 07:27
  • I'm not very sure, if the MessageBox not showed from the UI thread, it may not be on top of the main Form. check [so](http://stackoverflow.com/questions/2576156/winforms-how-can-i-make-messagebox-appear-centered-on-mainform) – Lei Yang Mar 10 '17 at 07:44
  • The form has only loading panel(progress bar). After opening a document, the form hides behind the document. After the close button in the document is clicked, i have code for showing the message box whether to save it in repository or not. – BalajiKasiraj Mar 10 '17 at 13:32
  • any one answer for my question – BalajiKasiraj Apr 05 '17 at 08:58

1 Answers1

1

Try the below:

DialogResult Secondpopups = MessageBox.Show(new Form() { TopMost = true },"Message u need to diaplay", "Title of the Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
GeralexGR
  • 2,973
  • 6
  • 24
  • 33