Hi,
is it possible to put an ArcGIS.Desktop.Framework.Dialogs.MessageBox in front of the "Closing Project" MessageBox?
Thanks Karsten
Hi Karsten,
I tried the following code which seemed to work fine. In essence i subscribe to the Project Closing event in my module class and execute your MessageBox logic in the subscription method.
First i changed the autoLocad property in the insertModule tag in my config.daml to true:
<SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>modules</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"><</SPAN>insertModule</SPAN> <SPAN class="attr-name token">id</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>ProjClosing_Module<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">className</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Module1<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">autoLoad</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>true<SPAN class="punctuation token">"</SPAN></SPAN> <SPAN class="attr-name token">caption</SPAN><SPAN class="attr-value token"><SPAN class="punctuation token">=</SPAN><SPAN class="punctuation token">"</SPAN>Module1<SPAN class="punctuation token">"</SPAN></SPAN><SPAN class="punctuation token">></SPAN></SPAN> .... <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>insertModule</SPAN><SPAN class="punctuation token">></SPAN></SPAN> <SPAN class="token tag"><SPAN class="token tag"><SPAN class="punctuation token"></</SPAN>modules</SPAN><SPAN class="punctuation token">></SPAN></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
This will ensure that my add-in is initialized regardless of any UI interactions.
In the Module's Initialize override i subscribe to the Project Closing event, and in OnProjectClosing i do the customization including the MessageBox.
<SPAN class="keyword token">protected</SPAN> <SPAN class="keyword token">override</SPAN> <SPAN class="keyword token">bool</SPAN> <SPAN class="token function">Initialize</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Core<SPAN class="punctuation token">.</SPAN>Events<SPAN class="punctuation token">.</SPAN>ProjectClosingEvent<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Subscribe</SPAN><SPAN class="punctuation token">(</SPAN>OnProjectClosing<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">base</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Initialize</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="comment token">/// <summary></SPAN> <SPAN class="comment token">/// Event handler for ProjectClosing event.</SPAN> <SPAN class="comment token">/// </summary></SPAN> <SPAN class="comment token">/// <param name="args">The ProjectClosing arguments.</param></SPAN> <SPAN class="comment token">/// <returns></returns></SPAN> <SPAN class="keyword token">private</SPAN> Task <SPAN class="token function">OnProjectClosing</SPAN><SPAN class="punctuation token">(</SPAN>ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Core<SPAN class="punctuation token">.</SPAN>Events<SPAN class="punctuation token">.</SPAN>ProjectClosingEventArgs args<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// if already canceled, ignore</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>args<SPAN class="punctuation token">.</SPAN>Cancel<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> Task<SPAN class="punctuation token">.</SPAN>CompletedTask<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> targetProjFolder <SPAN class="operator token">=</SPAN> <SPAN class="string token">@"c:\temp"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> result <SPAN class="operator token">=</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>$<SPAN class="string token">@"Soll das aktuelle Projekt in ein anderes Verzeichnis als {targetProjFolder} kopiert werden ?"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Projekt sichern"</SPAN><SPAN class="punctuation token">,</SPAN> System<SPAN class="punctuation token">.</SPAN>Windows<SPAN class="punctuation token">.</SPAN>MessageBoxButton<SPAN class="punctuation token">.</SPAN>YesNoCancel<SPAN class="punctuation token">,</SPAN> System<SPAN class="punctuation token">.</SPAN>Windows<SPAN class="punctuation token">.</SPAN>MessageBoxImage<SPAN class="punctuation token">.</SPAN>Question<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> Task<SPAN class="punctuation token">.</SPAN>CompletedTask<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
the Project closing messagebox doesn't show up until after i answer the popup messagebox.
Hope this helps,
Wolf
Hi Karsten, what is the workflow that you try to accomplish, in order words what event triggers the MessageBox that occurs with the 'Closing Project' message box?
I check the project path and if a part of that is set in the options, a MessageBox appears. The user can choose if the set save path in the options is right or not, can cancel the action.
How to call the MessageBox to show it always in foreground (right image)?
static void closedProject() {... if (appSettings.GeneralSetting1 == true && appSettings.GeneralSetting2 == sourceProjFolder.Substring(0, lensourceAppFolder)) { MessageBoxResult result = ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Soll das aktuelle Projekt in ein anderes Verzeichnis als " + targetProjFolder + " kopiert werden ?", "Projekt sichern", System.Windows.MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.Question);
static void closedProject() {...
if (appSettings.GeneralSetting1 == true && appSettings.GeneralSetting2 == sourceProjFolder.Substring(0, lensourceAppFolder)) {
MessageBoxResult result = ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Soll das aktuelle Projekt in ein anderes Verzeichnis als " + targetProjFolder + " kopiert werden ?", "Projekt sichern", System.Windows.MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.Question);
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.