Solved

How to Delete a LineShape Control

Posted on 2013-05-21
1
477 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 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

726 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