8 Replies - 18963 Views - Last Post: 21 March 2008 - 08:05 AM Rate Topic: -----

#1 killnine  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 161
  • Joined: 12-February 07

MessageBox to appear on top of main form

Posted 19 March 2008 - 06:23 AM

Any thoughts on how to keep a messagebox on top of the main form?

I have a form designed but messages from my thrown exceptions appear below the main form, which is annoying becuase users dont see them. Right now I just throw an exception and in my "catch" clause I say:

MessageBox.Show("Blah blah","Error",MessageBoxButtons.OK, MessageBoxIcon.Error);



nothing special. But it always appears on bottom...

One idea I had was to use the IWin32WinOwner argument, but I dont really know how to reference my main window, so any help would be appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: MessageBox to appear on top of main form

#2 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: MessageBox to appear on top of main form

Posted 19 March 2008 - 08:21 AM

not sure what you mean. are you looking to display the messagebox in a form or is it a Textbox displaying your message on the form.
Was This Post Helpful? 0
  • +
  • -

#3 killnine  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 161
  • Joined: 12-February 07

Re: MessageBox to appear on top of main form

Posted 19 March 2008 - 09:03 AM

View Postzakary, on 19 Mar, 2008 - 08:21 AM, said:

not sure what you mean. are you looking to display the messagebox in a form or is it a Textbox displaying your message on the form.



Lets assume I have a form where all my controls are and there is a textbox within that form. Lets also assume this textbox should only have integers put into it (no alpha characters, or numbers with a decimal).

If a user enters some invalid value, I throw an exception (myToolException, for instance).

When I catch the exception, I just show a messagebox that says something like "Invalid textbox input" or something like that.

However, right now, these messageboxes appear BELOW the main form.

Because its an exception, it pretty much halts all user input until the user selects "OK" on the messagebox. But because its below the main form, people dont often see it (and then they get frustrated).

But the thing is, it doesn't happen EVERY time, only sometimes. Sometimes the error pops up in front of the main form, but other times it doesn't.

Thoughts?
Was This Post Helpful? 0
  • +
  • -

#4 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: MessageBox to appear on top of main form

Posted 19 March 2008 - 09:48 AM

and you are using System.Windows.Forms.MessageBox.Show(""); to display your Exception message
Was This Post Helpful? 0
  • +
  • -

#5 killnine  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 161
  • Joined: 12-February 07

Re: MessageBox to appear on top of main form

Posted 19 March 2008 - 11:25 AM

View Postzakary, on 19 Mar, 2008 - 09:48 AM, said:

and you are using System.Windows.Forms.MessageBox.Show(""); to display your Exception message


Yup.
Was This Post Helpful? 0
  • +
  • -

#6 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: MessageBox to appear on top of main form

Posted 19 March 2008 - 12:22 PM

That is strange can you post your code so we can see what is going on.
Was This Post Helpful? 0
  • +
  • -

#7 killnine  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 161
  • Joined: 12-February 07

Re: MessageBox to appear on top of main form

Posted 20 March 2008 - 06:20 AM

View Postzakary, on 19 Mar, 2008 - 12:22 PM, said:

That is strange can you post your code so we can see what is going on.



I dont think my employer is too keen on me pasting any code right now.

I dont know if this fixed it, but I now use the following argument list

MessageBox.Show(this,"Some error text","Error Title",MessageBoxButtons.OK,MessageBoxIcon.Error);


Was This Post Helpful? 0
  • +
  • -

#8 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: MessageBox to appear on top of main form

Posted 20 March 2008 - 07:25 AM

try this

try
{

}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "Error Title",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
Was This Post Helpful? 0
  • +
  • -

#9 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: MessageBox to appear on top of main form

Posted 21 March 2008 - 08:05 AM

Could you post a screenshot of the Messagebox appearing behind the form?

This could possibly happen if your form's TopMost Property is set to True.
Was This Post Helpful? 1

Page 1 of 1