?
Solved

How to Delete a LineShape Control

Posted on 2013-05-21
1
Medium Priority
?
480 Views
Last Modified: 2013-05-21
The code below spawns a new lineshape when a user right-clicks and selects "connect" from a parent control's contextmenustrip.   Is there a way to add to the newly formed lineshape a right-click contextmenustrip with a "Delete" option to allow a user to delete a line that's not wanted?
  Private Sub ctmsconnect_Click(sender As System.Object, e As System.EventArgs) Handles ctmsconnect.Click
        ' Private Sub ctms_Click(sender As System.Object, e As System.EventArgs) Handles boxCtms1.Click
        mLineWidth = 1

        Dim myItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
        Dim cms As ContextMenuStrip = CType(myItem.Owner, ContextMenuStrip)
        'MessageBox.Show(boxCtms1.SourceControl.Name)
        Dim x As Integer = cms.SourceControl.Right - 2
        Dim y As Integer = cms.SourceControl.Top + (cms.SourceControl.Height / 2 - 12)
        Dim LS As New LineShape
        NumLineShapes += 1
        LS.Name = "LineShape" & NumLineShapes
        LS.BorderColor = Color.Black
        LS.BorderWidth = 2
        LS.Cursor = Cursors.Hand

        ' set starting and ending coordinates for the line
        LS.StartPoint = New Point(x, y)
        LS.EndPoint = New Point(x + 80, y - 5)
        'sLSTemp.StartPoint = New System.Drawing.Point(siSCCount * 20, 60 + siSCCount * 60)
        'sLSTemp.EndPoint = New System.Drawing.Point(100 + siSCCount * 20, 110 + siSCCount * 60)

        ' set new LineShape to top of z-order
        LS.BringToFront()
        LS.BringToFront()

        ' connect ContextMenuStrip to LineShape
        'LS.ContextMenuStrip = mLsCtm1
        ' add LineShape to ShapeContainer
        'myLS.Parent = mySC
        '  'Me.Controls.Add(mySC)

        numconnectedlineendpoints += 1
        Dim myValues As New List(Of String)
        myValues.Add(cms.SourceControl.Name)
        DropLineOriginalObjectName = cms.SourceControl.Name
        OrigDropControl = cms.SourceControl
        myValues.Add(LS.Name)
        'myValues.Add(mySC.Name)
        myValues.Add("linestart")
        dicGUIControls.Add(numconnectedlineendpoints, myValues)
       
        Lines.Add(LS)
        SC.Shapes.Add(LS)
        Me.Refresh()
        ' add handlers

    End Sub

Open in new window

0
Comment
Question by:lep1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1200 total points
ID: 39186215
This example should demonstrate what needs to be done:
Public Class Form1

    Private LS As LineShape

    Private R As New Random
    Private SC As New ShapeContainer
    Private CMS As New ContextMenuStrip
    Private WithEvents delete As ToolStripItem

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Controls.Add(SC)
        delete = CMS.Items.Add("Delete")
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim LS As New LineShape
        LS.BorderWidth = 2
        LS.Cursor = Cursors.Hand
        LS.StartPoint = New Point(R.Next(Me.Width), R.Next(Me.Height))
        LS.EndPoint = New Point(R.Next(Me.Width), R.Next(Me.Height))

        LS.ContextMenuStrip = CMS
        AddHandler LS.MouseDown, AddressOf LS_MouseDown

        SC.Shapes.Add(LS)
    End Sub

    Private Sub LS_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Right Then
            Me.LS = sender
        End If
    End Sub

    Private Sub delete_Click(sender As Object, e As System.EventArgs) Handles delete.Click
        If Not IsNothing(LS) Then
            SC.Shapes.Remove(LS)
            LS = Nothing
        End If
    End Sub

End Class

Open in new window

0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question