can messagebox be used in object not derived from winforms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can I actually use a messagebox within my own class which is not derived from
Forms?
Thanks,
 
If i understand correctly you want to be able to display msg box from any of
your classes
just include system.windows.forms;

or u can use it as this

//code
System.Windows.Forms.MessageBox.Show(param...);
//
 
I will have a problem to center it to the application window.
--
---He who will not economize will have to agonize. -----



raj said:
If i understand correctly you want to be able to display msg box from any of
your classes
just include system.windows.forms;

or u can use it as this

//code
System.Windows.Forms.MessageBox.Show(param...);
//
 
HomerW said:
I will have a problem to center it to the application window.

'MessageBox' doesn't support manual positioning, except with some ugly Win32
dialog hook hacks.
 
I'm I missing something? First you said that you want to show a message box
from within non-form class. I took it you don't have a form (e.g. console
application) and you want to show a message box from there. Now you are
talking about centering the box within your application, which means you do
have a form.

MessageBox is not a form, it uses MessageBox API to show the UI. It uses
also GetActiveWindow API to get the reference to the window that is going to
be used as owner, therefore it doesn't care where you show the message box
or how you create the application windows.

However message boxes are modal, which means one cannot switch to the main
UI until dismiss the message box. In order to work this way the message box
needs to be shown from the same thread that has created the main application
UI.

Regrading centering the message box I don't think you have options there.
Message boxes are always centered against the the desktop.


--

Stoitcho Goutsev (100) [C# MVP]

HomerW said:
I will have a problem to center it to the application window.
 
Back
Top