Solved

How to Delete a LineShape Control

Posted on 2013-05-21
1
466 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
1 Comment
 
LVL 85

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now