Example 2: MS Dev Studio C# WPF
This example is a C# application using the PTC Mathcad Prime API to exercise some fundamental methods and properties, and to demonstrate how to enable events. This example mimics the functionality of the C++.NET example.
There are two main pieces of code:
• MainWindow.xaml.cs builds the user interface.
• ComEvents2.cs implements the methods of the MathcadPrimeComEvents2 class that tells PTC Mathcad Prime what to do on event.
MainWindow.xaml.cs starts Mathcad. This callback creates a MathcadPrimeApplication3 and a MathcadPrimeComEvents2 object. These PTC Mathcad Prime objects are part of the API, and are the only two objects that you create with new. Note that in C#, we create ApplicationCreator(). After you create the MathcadPrimeComEvents2 object, you can implement the methods in terms of what you want to happen upon events, including OnExit and OnWorksheetClosed. There are a total of eight events.
1. Download the example here:
C#.NET.
2. To run the example, execute ExampleDotNetComClientSimpl.exe. The C# .NET COM Client – Example dialog window opens:
3. Click Start Mathcad Prime and wait until PTC Mathcad Prime opens.
4. Click Show Mathcad Prime to bring PTC Mathcad Prime to the foreground.
5. Click Hide Mathcad Prime to hide PTC Mathcad Prime.
6. Click Open Worksheet to browse to the worksheet that you want to open. Open the worksheet.
7. Click Open New Worksheet and ensure a new worksheet entitled Untitled-n opens.
8. Click Close Worksheet and ensure the last opened worksheet is closed.
9. To check the events:
a. Click Enable Events.
b. Click the worksheet and type something. A message appears indicating a modified event occurred. Click OK to dismiss the message.
c. Click Save As. A message appears indicating a renamed event occurred. Click OK to dismiss the message.
d. Click Close Worksheet. A message appears indicating a close event occurred. Click OK to dismiss the message.
10. In PTC Mathcad Prime, click > , and then in C# .NET COM Client – Example dialog window click > .