25 July 2008

Plot Preview Gotcha

Here's a quick fix to a really annoying problem I was having. If you're making a custom plot routine using a modal form and have included plot preview functionality you'll quickly realize that as soon as the plot preview is displayed you're stuck. Completely stuck, escape key, right-click, everything is frozen. Apparently your plot form still has focus, even if hidden.

There's two fixes for this problem:

1) Use a modeless form. This includes adding document locks almost everywhere and is generally a pain in the butt.

2) Add a User Interaction, like this:

  Private Sub PlotPreview()

    Dim edUserInteraction As EditorUserInteraction = Application.DocumentManager.MdiActiveDocument.Editor.StartUserInteraction(Me)

 

    Try

      Me.Hide()

 

      ' Do your plot preview

 

    Catch ex As System.Exception

      ' Error handling

    Finally

      edUserInteraction.End()

 

      ' Show the form

      If Me.Visible = False Then Me.Show()

    End Try

  End Sub


The EditorUserInteraction object allows your modal form to give up focus and allow the plot preview to do what it's supposed to.

Simple fix for a very frustrating problem.

No comments:

Disclaimer

All materials on this site are provided "as is" and without any warranty. Any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the authors be liable to any party for any direct, indirect, incidental, special, exemplary, or consequential damages arising in any way out of the use or misuse of this site.