2013-11-16 3 views
0
Private Sub lstrecentdocs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstrecentdocs.SelectedIndexChanged 

    If lstrecentdocs.SelectedIndex = -1 Then 
     lstrecentdocs.ContextMenuStrip = Nothing 
    Else 
     lstrecentdocs.ContextMenuStrip = ContextMenuStrip2 
    End If 
End Sub 

В ListBox В Пустое пространство есть ...... при выборе элементов в ListBox он отображает меню Contex Правильно, но если элемент выделен и щелкнет в любом месте ListBox, он отображает контекстное меню .... .......Проблема с контекстным меню

Мое требование - при выборе элементов, которые он показывает contexmenu в надлежащем месте, только там, где выбран элемент.

Спасибо заранее ......

ответ

0

Private Sub lstrecentdocs_MouseUp_1 (ByVal отправитель Как System.Object, ByVal е Как System.Windows.Forms.MouseEventArgs) Ручки lstrecentdocs.MouseUp

Try 
     If e.Button = Windows.Forms.MouseButtons.Right Then 
      Dim index = lstrecentdocs.IndexFromPoint(e.Location) 
      If index >= 0 Then 
       lstrecentdocs.SelectedIndex = index 
       ContextMenuStrip2.Show(lstrecentdocs, e.Location) 
      Else 
       ContextMenuStrip2.Visible = False 
      End If 
     End If 
    Catch ex As Exception 
     MsgBox(ex.Message) 
    End Try  
End Sub 
Смежные вопросы