VB2010で目標はフォーム上で作成したLINESHAPEをクリックして消去する事です 下記のようにコードを書いてみました Imports Microsoft.VisualBasic.PowerPacks Public Class Form1 Private px1 As Integer = 0 Private px2 As Integer = 0 Private py1 As Integer = 0 Private py2 As Integer = 0 Private curv As LineShape Private a As Boolean = True Private flg As Boolean = True Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load // 座標と始点・終点フラグの初期化 px1 = 0 px2 = 0 py1 = 0 py2 = 0 a = True End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click // SHAPECONTAINER の用意 Dim canvasx As New ShapeContainer // LINESHAPE の用意 Dim ls1 As New LineShape // LineShape インスタンス設定 canvasx.Parent = Me ls1.Name = "curv" ls1.Parent = canvasx ls1.BorderColor = Color.Lime ls1.SelectionColor = Color.Green ls1.X1 = px1 ls1.X2 = px2 ls1.Y1 = py1 ls1.Y2 = py2 // ShapeContainer のコントロールコレクションへの追加 Me.Controls.Add(canvasx) End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click // 座標と始点・終点フラグの初期化 px1 = 0 px2 = 0 py1 = 0 py2 = 0 a = True End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click //CURV_CLiCKのイベントの登録 AddHandler curv.Click, AddressOf curv_Click End Sub Private Sub Form1_Click(sender As System.Object, e As System.EventArgs) Handles MyBase.Click // Lineの座標を拾う Dim Pos As Point = Me.PointToClient(Windows.Forms.Cursor.Position) If a = True Then px1 = Pos.X py1 = Pos.Y a = False Else px2 = Pos.X py2 = Pos.Y End If End Sub Private Sub curv_Click(sender As System.Object, e As System.EventArgs) // クリックされたLineShapeの消去のつもり、テスト未完 For Each obj In Me.Controls If obj = sender Then obj = Nothing End If Me.Refresh() Next End Sub End Class 書かれた直線をクリックしても何も起きません。LineShape は確かにハイライト色に変化するのですが、イベントが発生しません なにとぞご教授を
↧