Bring Windows form to front after ArcMap Refresh Happens

2221
0
11-26-2014 01:19 PM
JamariPowers
New Contributor III

I am working in Arc Map using C#. Overall project I'm working on is an Add-In. I have a simple form. This form is displayed from a button click from a toolbar. I click on my button and my form comes up -- simple. I wanted to check to see if the form was open first. If it is, then bring it to the front. If its not, then create a new instance of it and open/show it. Code is as follows

namespace MapProject
{
   public class cmdMapProject : ESRIS.ArcGIS.Desktop.AddIns.Button
   {
      public MpInterface _myForm;

      protected override void OnClick()
      {
      if (_myForm != null)
      {
         _myForm.Activate();
         _myForm.BringToFront();
         _myForm.Focus();
      }
      else 
      {
         myForm = new MpInterface();
         _myForm.Disposed += new EventHandler(_myForm_Disposed);
         _myForm.Show();
      }
      }
      private void _myForm_Disposed(object sender, EventArgs e)
        {
            _myForm = null;    
        }
    }
}

Clearly I've tried a few different members to get this thing to show. My problem I can best explain is scenarios

(1) Click button from toolbar, opens up form, click somewhere in map document, click button from toolbar, my form comes to front  --> OK

(2) Click button from toolbar, opens up form, close form, click button from toolbar, my form opens  -->  OK

(3) Click button from toolbar, opens up form, interact with form, functionality runs, form goes to back, click button from toolbar --> My form flickers. It appears and then goes back to the back. It doesn't open a new form, which is good, but it just flickers. It comes to front then goes to back

(4) Click button from toolbar, opens up form, interact with form, functionality runs, close form, click button from toolbar --> My new form opens up but as soon as it opens, it goes to the back. And once it goes to the back I'll click my toolbar button again, and it flickers again. It shows its self and then disappears (or goes to the back).

I'm not sure whats causing this or how to fix this. Now, one thing is that, when I interact with the map and functionality is ran, an ArcMap refresh is being called within that functionality. Its just refreshing data in the elements. I myself am not setting any thin from this refresh. Maybe ArcMap is setting something. I'm not sure. Maybe it has to deal with multi threading, I'm not sure. But any help on this would be greatly appreciated. Thanks in advance.

0 Kudos
0 Replies