1

I am working with ArcMap and C#. In the bottom left hand corner, there is a menu where you can toggle between Data view and Layout View, a Pause button, and a refresh button. I have created an Add-in for ArcMap. I need to run some code when the Refresh button is clicked. Does anyone know the name of the event handler that controls the Refresh button? Or would anyone have some type of example where some code runs every time the Refresh button is clicked?

1

You probably just need to use the IActiveView.Refresh method to achieve what you're looking for. You can get the active view from the MxDocument.ActiveView property. The help/snippets should lead you the rest of the way.

  • 1
    Thank you for your input. I have used the IActiveView.Refresh method before. I use it now in my current code. I use it more so as a 'call' at the end of one of my functions (if that made sense lol). I didn't see it had too much to do with the actual refresh button thats in the bottom left had corner though. I need that specific button handle. – user1898629 Oct 6 '14 at 15:19
1

You will need to track the current active view and unhook the old active view (required|optional ?) and hook the new active view whenever it changes.

Note that ViewRefreshed is not called every time the view is actually redrawn, but it does seem to be called whenever the code explicitly calls Refresh or PartialRefresh and when the redraw toolbar button you mention is clicked.

So something like:

  • MyApp is some way you access IApplication.
  • MyApp.MxDocument is some way you access IMxDocument.
  • avCurrent is an IActiveView member in your class.
public static void Listen( bool LISTEN )
{
    if( listen == LISTEN || MyApp == null ) return;

    var doce = MyApp.Document as IDocumentEvents_Event;

    if( LISTEN ) {
        if( doce != null ) {
            doce.ActiveViewChanged += onActiveViewChanged;
        }
    }
    else {
        if( doce != null ) {
            doce.ActiveViewChanged -= onActiveViewChanged;
        }
    }

    listen = LISTEN;
}

public static void ListenActiveView( bool LISTEN )
{
    if( listenActiveView == LISTEN ) return;

    var ave = avCurrent as IActiveViewEvents_Event;
    if( ave == null ) ave = MyApp.MxDocument.ActiveView as IActiveViewEvents_Event;

    if( LISTEN ) {
        if( ave != null ) {
            ave.ViewRefreshed += onViewRefreshed;
            ave.AfterDraw     += onAfterDraw;
        }
        avCurrent = ave as IActiveView;
    }
    else {
        if( ave != null ) {
            ave.AfterDraw     -= onAfterDraw;
            ave.ViewRefreshed -= onViewRefreshed;
        }
        avCurrent = null;
    }

    listenActiveView = LISTEN;
}

protected static void onActiveViewChanged()
{
    ListenActiveView(false);  // stop  listening to old
    ListenActiveView(true);   // start listening to new
}

protected static void onViewRefreshed( IActiveView VIEW, esriViewDrawPhase PHASE, object DATA, IEnvelope ENVELOPE )
{ ... }

protected static void onAfterDraw( IDisplay DISPLAY, esriViewDrawPhase PHASE )
{ ... }
0

There is the event IActiveViewEvents.ViewRefreshed.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • Thanks for your input. I will take a more in depth look at this method and see what I can find. – user1898629 Oct 6 '14 at 15:20
0

The code below works for me.

 var pMapDoc = this.MapApp.Document;
IUID pUid = new UIDClass();
pUid.Value = "esriArcMapUI.RefreshViewCommand";
var pCommandItem = pMapDoc.CommandBars.Find(pUid);
 pCommandItem.Execute();  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.