MapWindow 4 - Plugins : MapWindow Discussion Forum
I am attempting to add a context menu that will open when the user right clicks the map area of MapWindow. The C# context menu requires a handle to the calling object so that it doesn't open when the mouse button is pressed on the wrong handle. Is there a way to get a handle to the map area from w
Adding a (Right-click) context menu
Posted by: Chad ()
Date: May 16, 2009 04:05PM

I am attempting to add a context menu that will open when the user right clicks the map area of MapWindow. The C# context menu requires a handle to the calling object so that it doesn't open when the mouse button is pressed on the wrong handle. Is there a way to get a handle to the map area from within C# code?

-Chad



Edited 1 time(s). Last edit at 05/18/2009 12:02PM by Chad.

Options: ReplyQuote
Re: Adding a (Right-click) context menu
Posted by: pmeems ()
Date: May 19, 2009 02:07PM

Chad,

I don't think I understand.

Could you post some sample code?

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Options: ReplyQuote
Re: Adding a (Right-click) context menu
Posted by: JimJohnD ()
Date: May 19, 2009 02:35PM

First you will need to set up for the menu-events like this:
Friend WithEvents mnuContextSE As New System.Windows.Forms.ContextMenuStrip
Friend WithEvents mnuSE_SelectParcel As New System.Windows.Forms.ToolStripMenuItem
Friend WithEvents mnuSE_ParcelReview As New System.Windows.Forms.ToolStripMenuItem
Friend WithEvents mnuSE_MenuSep1 As New System.Windows.Forms.ToolStripSeparator
Friend WithEvents mnuSE_NewDwelling As New System.Windows.Forms.ToolStripMenuItem
Friend WithEvents mnuSE_NewOutbuilding As New System.Windows.Forms.ToolStripMenuItem

This will allow you to trap for the events.
>>>>>>>>>>>>>>>>>>>
In your initialization code you will need something like this:
mnuContextSE = New System.Windows.Forms.ContextMenuStrip()
mnuContextSE.SuspendLayout()

'
'mnuSE_SelectParcel
'
mnuSE_SelectParcel.Name = "mnuSE_SelectParcel"
mnuSE_SelectParcel.Size = New System.Drawing.Size(235, 22)
mnuSE_SelectParcel.Text = "Select Current Parcel"
'
'mnuSE_ParcelReview
'
mnuSE_ParcelReview.Name = "mnuSE_ParcelReview"
mnuSE_ParcelReview.Size = New System.Drawing.Size(235, 22)
mnuSE_ParcelReview.Text = "Review Selected Parcel"
'
'mnuSE_MenuSep1
'
mnuSE_MenuSep1.Name = "mnuSE_MenuSep1"
mnuSE_MenuSep1.Size = New System.Drawing.Size(235, 22)
mnuSE_MenuSep1.Text = "-"
'
'mnuSE_NewDwelling
'
mnuSE_NewDwelling.Name = "mnuSE_NewDwelling"
mnuSE_NewDwelling.Size = New System.Drawing.Size(235, 22)
mnuSE_NewDwelling.Text = "Add a new dwelling to the selected parcel"
'
'mnuSE_NewOutbuilding
'
mnuSE_NewOutbuilding.Name = "mnuSE_NewOutbuilding"
mnuSE_NewOutbuilding.Size = New System.Drawing.Size(235, 22)
mnuSE_NewOutbuilding.Text = "Add a new outbuilding to the selected parcel"
'
'mnuContextSE
'
mnuContextSE.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuSE_SelectParcel, Me.mnuSE_ParcelReview, Me.mnuSE_MenuSep1, Me.mnuSE_NewDwelling, Me.mnuSE_NewOutbuilding})
mnuContextSE.Name = "mnuContextSE"
mnuContextSE.ShowImageMargin = False
mnuContextSE.Size = New System.Drawing.Size(236, 70)

Me.mnuContextSE.ResumeLayout(False)

>>>>>>>>>>>>>>>>>>>>>>>>>>>
This creates the menu.

Then in the plug-in code set add something like this:
Public Sub MapMouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Integer, ByVal y As Integer, ByRef Handled As Boolean) Implements MapWindow.Interfaces.IPlugin.MapMouseUp
If g_MapWin.View.CursorMode = MapWinGIS.tkCursorMode.cmSelection Then
If Button = 2 Then
g_MapWin.StatusBar.Item(2).Text = ""
g_MapWin.StatusBar.Item(3).Text = ""

Dim point As System.Drawing.Point = New System.Drawing.Point(x, y)
g_MapWin.View.PixelToProj(x, y, MyX, MyY)

Dim MyPoint As New MapWinGIS.Point
Dim MyShape As New MapWinGIS.Shape
MyShape.ShapeType = MapWinGIS.ShpfileType.SHP_POINT

MyPoint.x = MyX
MyPoint.y = MyY
MyShape.InsertPoint(MyPoint, 0)

Dim PointPN As String = String.Empty
PointPN = ParcelByShapeExtents(MyShape, 0)
If PointPN > String.Empty Then
g_SelectedParcelNumber = ParcelByShapeExtents(MyShape, 0)
g_MapWin.Plugins.BroadcastMessage("ParcelSelected:" & g_SelectedParcelNumber)

Dim PHD As Long = 0
Dim PHDA As Long = 0
Dim PHO As Long = 0
Dim PHOA As Long = 0

PHD = Globals.ParcelHasDwellings(g_SelectedParcelNumber, False)
PHDA = Globals.ParcelHasDwellings(g_SelectedParcelNumber, True)

If PHD > 0 Then
If PHD > PHDA Then
mnuSE_NewDwelling.Enabled = True
Else
mnuSE_NewDwelling.Enabled = False
End If
Else
mnuSE_NewDwelling.Enabled = False
End If

PHO = Globals.ParcelHasOutbuildings(g_SelectedParcelNumber, False)
PHOA = Globals.ParcelHasOutbuildings(g_SelectedParcelNumber, True)

If PHO > 0 Then
If PHO > PHOA Then
mnuSE_NewOutbuilding.Enabled = True
Else
mnuSE_NewOutbuilding.Enabled = False
End If
Else
mnuSE_NewOutbuilding.Enabled = False
End If

g_MapWin.StatusBar.Item(2).Text = "PN:" & PointPN
g_MapWin.StatusBar.Item(3).Text = "Edited/Total Dwellings:" & PHDA & "/" & PHD & " Outbuildings:" & PHOA & "/" & PHO

Me.mnuContextSE.Show(g_MapWin.GetOCX, point)
End If
End If
End If
End Sub
>>>>>>>>>>>>>>>>>>>>>>>>>
Doing it this way you can control the appearance of the sub-menus. Being in the mouse-up event of the MWControl you don't have to worry about errant clicks (on a toolbar) bringing up your menu.

Hope that helps.
JimJohnD

Options: ReplyQuote
Re: Adding a (Right-click) context menu
Posted by: seum ()
Date: August 26, 2010 07:33AM

hi,
i'm using visual c++ (vs2005/2008 development environment)
to use the activex, i'm using the windows forms; in it, is possible to define, in the control properties, the ContextMenuStrip associated.
When i run the application, after a right-click on the control, no menu appears...
Is it the right behavior or i need to do some other thing to use the menu?

thanks for your help!

Options: ReplyQuote
Re: Adding a (Right-click) context menu
Posted by: nmb100 ()
Date: August 27, 2010 12:56AM

Hi Chad

I have found the easiest to use, and managed, for right clicks context menus, is to create a form with the context menu attached, then when you load your plugin, load the form but don't make it visible. You are then able to access the context menu from a right click.

Hope this helps.

Nigel

Options: ReplyQuote
Re: Adding a (Right-click) context menu
Posted by: jhedtmann ()
Date: November 08, 2010 01:10PM

Hi,

in your plugin main, you could attach the context menu to the MouseDown event and set the Handled parameter to true. That way you direct all application attention to your context menu.

Hope, this helps.

Jörg Hedtmann, Dipl.-Päd.
Senior Software Engineer
E.O.D.-Specialist (Field Officer)
ROV-Pilot/-Engineer

Geo-Marine Consult
"La Casa Azul"
26 Ayas Trias/Αγία Τριάς
Ριζοκάρπασο/Dipkarpaz
Cyprus,Kıbrıs,Κύπρος

phone +90.542.8868790
alt. +357.96.522034
mobile +49.176.21967607

eMail joerg.hedtmann [AT] geomarineconsult.com

Options: ReplyQuote


Sorry, only registered users may post in this forum.





Banner Exchange




GISCP.com




Send us your banner logo (160x120) for the space above, and add this MapWindow banner ad to your site:

Just paste this text in your page: