Location of ContextMenuStrip

Hi!
I have an problem with my Media Player.
Im using a code i found somewhere on the forum (made by Bruno Yu) and its giving me a little problem...
when i open my context menu strip (CMS), it opens at the left top courner and sometimes i dont see the CMSStick out tongue
So now im trying something like this:

CMS1.Show()
CMS1.Location = New Point(CMS1.Location.X + 12, CMS1.Location.Y + 72)

But as some of you would know, that does not work, the CMS still opens in the left top courner.
So how can i make that the Context Menu Strip opens in the left top courner of the form?
(LEFT TOP COURNEROF THE FORM, not of my screen).
Here's my code if its any help for anyone:

*************--

Imports System.IO

Public Class Form5
Private WithEvents zTimer As New Windows.Forms.Timer

Private zUpdatedSelectedIndex As Integer = -1

Private Sub Form5_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

With zTimer

.Interval = 100

.Enabled = True

.Start()

End With

Me.Init_CMS1()

End Sub

Private Sub Init_CMS1()

CMS1.Items.Clear()

CMS1.Items.Add(New ToolStripMenuItem("V?lj Ny Mapp", Nothing, AddressOf SelectFolderToolStripMenuItem_Click))

CMS1.Items.Add(New ToolStripSeparator)

End Sub

Private Sub SelectFolderToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Static zSelectedFolder As String = "c:\"

Dim zRightClickLocation As Point = System.Windows.Forms.Cursor.Position

Dim zFBD As New FolderBrowserDialog

With zFBD

.Description = "V?lj en mapp att ladda in l?tar fr?n"

.SelectedPath = zSelectedFolder

.ShowNewFolderButton = False

.ShowDialog(Me)

End With

zSelectedFolder = zFBD.SelectedPath

Me.CreatePlayListItems(zSelectedFolder)

CMS1.Show(zRightClickLocation)

End Sub

Private Sub CreatePlayListItems(ByVal zGivenFolder As String)

' Get all the playlists from the given folder

Dim zPlayListFiles As New List(Of String)(My.Computer.FileSystem.GetFiles(zGivenFolder, FileIO.SearchOption.SearchTopLevelOnly, New String() {"*.wpl", "*.pl", "*.m3u", "*.asx"}))

' Clear the contextmenustrip

Me.Init_CMS1()

Dim zPlayList As WMPLib.IWMPPlaylist

Dim zPlayListMenuItem As ToolStripMenuItem = Nothing

Dim zTrack As WMPLib.IWMPMedia3

Dim zTrackMenuItem As ToolStripMenuItem = Nothing

For Each zFilePath As String In zPlayListFiles

zPlayList = AxWMP1.newPlaylist(Path.GetFileName(zFilePath), zFilePath)

zPlayListMenuItem = New ToolStripMenuItem(zPlayList.name, Nothing, AddressOf PlayListToolStripMenuItem_Click)

zPlayListMenuItem.Tag = zPlayList

zPlayListMenuItem.Owner = CMS1

If zPlayList.count > 0 Then

Dim zListOfTracks As New List(Of ToolStripMenuItem)

For zIndex As Integer = 0 To zPlayList.count - 1

zTrack = zPlayList.Item(zIndex)

zTrackMenuItem = New ToolStripMenuItem(zTrack.name, Nothing, AddressOf TrackToolStripMenuItem_Click)

zTrackMenuItem.Tag = zIndex

zListOfTracks.Add(zTrackMenuItem)

Next

zPlayListMenuItem.DropDownItems.AddRange(zListOfTracks.ToArray)

End If

Next

End Sub

Private Sub PlayListToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)

' When a playlist is clicked, set the parent playlist as the current playlist and start the first track

Dim zPlayListMenuItem As ToolStripMenuItem = sender

Dim zPlayList As WMPLib.IWMPPlaylist = zPlayListMenuItem.Tag

If zPlayList.isIdentical(AxWMP1.currentPlaylist) Then

' don't do anything

Else

' load the new playlist

AxWMP1.currentPlaylist = zPlayList

If zPlayList.count > 0 Then

' Load playlist into LB1 (=ListBox) by putting them all in a list first and then adding to the listbox (->faster)

LB1.Items.Clear()

Dim zListOfTracks As New List(Of String)

Dim zSelectedTrackIndex As Integer = 0

For zIndex As Integer = 0 To zPlayList.count - 1

' Note: after pulling out the hair on my head (and chest), I'm now assuming that the WMP doesn't

' provide its own PlaylistIndex to keep track of the current item, so I'm adding one myself.

zPlayList.Item(zIndex).setItemInfo("PlaylistIndex", zIndex.ToString)

zListOfTracks.Add((zIndex + 1).ToString("00") & ") " & zPlayList.Item(zIndex).name & " (" & zPlayList.Item(zIndex).durationString & ")")

Next

LB1.Items.AddRange(zListOfTracks.ToArray)

LB1.SelectedIndex = 0

End If

' close the contextmenustrip

CMS1.Close(ToolStripDropDownCloseReason.ItemClicked)

End If

End Sub

Private Sub TrackToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)

' When a track is clicked, set the parent playlist as the current playlist and select the track to play

Dim zTrackMenuItem As ToolStripMenuItem = sender

Dim zPlayListMenuItem As ToolStripMenuItem = zTrackMenuItem.OwnerItem

Dim zPlayList As WMPLib.IWMPPlaylist = zPlayListMenuItem.Tag

Dim zTrack As WMPLib.IWMPMedia3 = zPlayList.Item(zTrackMenuItem.Tag)

Dim zSelectedTrackIndex As Integer = -1

If zPlayList.isIdentical(AxWMP1.currentPlaylist) Then

' just set ListBox's SelectedIndex to the selected track

[Integer].TryParse(zTrack.getItemInfo("PlaylistIndex"), zSelectedTrackIndex)

LB1.SelectedIndex = zSelectedTrackIndex

Else

' load the new playlist and set the selected track

AxWMP1.currentPlaylist = zPlayList

' Load playlist into LB1 (=ListBox) by putting them all in a list first and then adding to the listbox (->faster)

LB1.Items.Clear()

Dim zListOfTracks As New List(Of String)

For zIndex As Integer = 0 To zPlayList.count - 1

' Note: after pulling out the hair on my head (and chest), I'm now assuming that the WMP doesn't

' provide its own PlaylistIndex to keep track of the current item, so I'm adding one myself.

zPlayList.Item(zIndex).setItemInfo("PlaylistIndex", zIndex.ToString)

zListOfTracks.Add((zIndex + 1).ToString("00") & ") " & zPlayList.Item(zIndex).name & " (" & zPlayList.Item(zIndex).durationString & ")")

If zPlayList.Item(zIndex).sourceURL = zTrack.sourceURL Then

zSelectedTrackIndex = zIndex

End If

Next

LB1.Items.AddRange(zListOfTracks.ToArray)

' Setting the Listbox's SelectedIndex will also set the WMP's Ctlcontrols.currentItem

LB1.SelectedIndex = zSelectedTrackIndex

End If

End Sub

Private Sub LB1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles LB1.SelectedIndexChanged

' when an item in the listbox is clicked, set that track as the currentitem

If LB1.SelectedIndex > -1 Then

AxWMP1.Ctlcontrols.currentItem = AxWMP1.currentPlaylist.Item(LB1.SelectedIndex)

AxWMP1.Ctlcontrols.playItem(AxWMP1.Ctlcontrols.currentItem)

End If

End Sub

Private Sub AxWMP1_CurrentItemChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_CurrentItemChangeEvent) Handles AxWMP1.CurrentItemChange

Dim zNewTrack As WMPLib.IWMPMedia3 = e.pdispMedia

If zNewTrack IsNot Nothing Then

' Note: I'm using zTimer and the zUpdatedSelectedIndex variable to set the new listbox.selectedindex because

' there are LoaderLock errors if you try to update the managed Listbox directly within this eventsub

Dim zSelectedIndex As Integer = -1

[Integer].TryParse(zNewTrack.getItemInfo("PlaylistIndex"), zSelectedIndex)

zUpdatedSelectedIndex = zSelectedIndex

End If

End Sub

Private Sub zTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles zTimer.Tick

If zUpdatedSelectedIndex > -1 Then

LB1.SelectedIndex = zUpdatedSelectedIndex

zUpdatedSelectedIndex = -1

End If

End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
CMS1.Show()
End Sub
Private Sub ?ppnaL?tToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ?ppnaL?tToolStripMenuItem.Click
CMS1.Location = New System.Drawing.Size(305, 26)
CMS1.Show()
CMS1.Location = New Point(CMS1.Location.X + 12, CMS1.Location.Y + 72)
End Sub
End Class
*************--

//Greetings, Zeelia.
PS: I hope you can help me!

[8608 byte] By [Zeelia] at [2008-1-10]
# 1
Use the ContextMenuStrip.Show(Control, Integer, Integer) overload. For example, this code shows the CMS at the far left corner of the form, just underneath the menu strip:

Private Sub TestToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestToolStripMenuItem.Click
ContextMenuStrip1.Show(Me, 0, MenuStrip1.Bottom)
End Sub

nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Hi!
I just wanted to say that this helped so thanks!
//Greetings from thankfully Zeelia
Zeelia at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...