SE AddIn Message Box C#

Experimenter
Experimenter

Hello,

 

I like to make an SE AddIn witch copy the material info before save. This is already working.

 

Now I would like that a Message Box opens, when there was a fault.

 

Please can you help me how I can display a message or a message box

 

Thank you for the help

2 REPLIES

Re: SE AddIn Message Box C#

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

In order to correctly show a MessageBox from an addin, you need to specify the "owner" of the dialog. To do that, you need a reference to a NativeWindow as shown below.

 

try
{
    throw new System.Exception("Test");
}
catch (System.Exception ex)
{
    IntPtr phWnd = new IntPtr(application.hWnd);
    System.Windows.Forms.NativeWindow owner = System.Windows.Forms.NativeWindow.FromHandle(phWnd);
    System.Windows.Forms.MessageBox.Show(owner, ex.Message, "Exception");
}

For further reading, you might take a look at my ShowDialog for Form and ShowDialog for CommonDialog extension methods of the SolidEdgeFramework.Application type on GitHub. That is the code behind my SolidEdge.Community NuGet package. You didn't specify how you've created your addin but my Solid Edge Community Templates Quick Start video is worth mentioning. It covers the Solid Edge Community Templates for Visual Studio and how to easily create an addin using the templates.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: SE AddIn Message Box C#

Experimenter
Experimenter

Thank you for your help, It works perfekt.