Share via


Information Pop-ups in WinForms

We've had several questions about how to do a pop-up form in WinForms, similar to the one on the website.  The website pop-up is implemented entirely within the browser, using an IFrame.  Therefore, the functionality does not exist by default in the managed code alone.  However, the events you need are provided, and creating your own pop-up is not difficult.

Html rendered pop-up

The event you need is EngineEvents.OnHover, accessed via the CommunicationManager.  It will fire when the mouse hovers over any GeometryManager object that has hit detection on.  The event arguments (CommunicationParameters) tell you which item was hovered and where on the screen it is.  I used the Tag property on WorldGeometry to hold the name and description I wish to display, so when I get the hover event I retrieve the item back again and pass the tag to my Popup form.

The next step is to render the form.  There are two behaviors we want:  first, the auto-closing.  This was pretty simple to do using a Timer.  When you get an OnHoverEnd (another EngineEvent), start a timer.  If the mouse moves into the popup, stop the timer.  When the mouse leaves it, start the timer again.  The second behavior is rendering HTML.  This was trivial on the website, but a little tricker in winforms.  Fortunately Windows ships with mshtml, which has a ready-made browser window.  I based my work on this, and had it working in just a few minutes.

I'm certain all of this could be done more attractively and elegantly, but it should get you started.  I updated the main samples package to have the new HtmlForm project.  Just grab the zip file again and pull out that project directory.

Get the code!

P.S.  If you want to open an ERO from a plug-in without having to go through the JS API first, do this:

CommunicationParameterSet set =

new CommunicationParameterSet(8);
set.Add("layerId", null);
set.Add("pushpinId", null);
set.Add("rX1", p.X);
set.Add("rY1", p.Y);
set.Add("rX2", p.X);
set.Add("rY2", p.Y);
set.Add("header", name);
set.Add("content", desc == null ? string.Empty : desc);
Host.CommunicationManager.FireEvent(EngineEvents.Group, EngineEvents.OnHover, set);

p is the location on the screen you want it, name is the title, and desc is your html content.

Comments