Add-in with MessageBox

294
1
Jump to solution
10-24-2017 11:21 AM
Highlighted
Occasional Contributor II

Hi there,

how can I write an add-in that shows a Message Box when the project is loaded? I want to give the user some new informations, when he starts a new project?

Thanks,

Karsten

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Regular Contributor

Hi,

You can subscribe to the ProjectOpenedEvent (topic9319) to accomplish this.  Additionally, the add-in will need to load as soon as Pro launches, so you will have to set the "autoload" attribute to true in the config.daml of the  add-in.  Code snippets below:

In the Module class of the add-in:

 protected override bool Initialize()
        {
            ProjectOpenedEvent.Subscribe(OnProjectOpened); //subscribe to event
            return base.Initialize();
        }

        private void OnProjectOpened(ProjectEventArgs obj)
        {
            MessageBox.Show($"{Project.Current} has opened"); //show your message box
        }

        protected override void Uninitialize()
        {
            ProjectOpenedEvent.Unsubscribe(OnProjectOpened); //unsubscribe
            return;
        }

In your config.daml, set the autoload attribute to true so that the add-in loads when Pro launches:

...
<modules>
    <insertModule id="SubscribeProjectLoad_Module" className="Module1" autoLoad="true" caption="Module1">
...

Thanks

Uma

View solution in original post

1 Reply
Highlighted
Esri Regular Contributor

Hi,

You can subscribe to the ProjectOpenedEvent (topic9319) to accomplish this.  Additionally, the add-in will need to load as soon as Pro launches, so you will have to set the "autoload" attribute to true in the config.daml of the  add-in.  Code snippets below:

In the Module class of the add-in:

 protected override bool Initialize()
        {
            ProjectOpenedEvent.Subscribe(OnProjectOpened); //subscribe to event
            return base.Initialize();
        }

        private void OnProjectOpened(ProjectEventArgs obj)
        {
            MessageBox.Show($"{Project.Current} has opened"); //show your message box
        }

        protected override void Uninitialize()
        {
            ProjectOpenedEvent.Unsubscribe(OnProjectOpened); //unsubscribe
            return;
        }

In your config.daml, set the autoload attribute to true so that the add-in loads when Pro launches:

...
<modules>
    <insertModule id="SubscribeProjectLoad_Module" className="Module1" autoLoad="true" caption="Module1">
...

Thanks

Uma

View solution in original post