dポイントプレゼントキャンペーン実施中!

VS(Visual Basic2012)でアプリケーションの開発をしております。

WindowsフォームアプリケーションにてForm上のPanelにコンテナされている
Pictureboxに、Buttonをクリックする度にLineshapeコントロールを動的に配置するようにしています。

そこで、とある動作(他のButtonのクリックとか)で、
そのなかの特定のLineshapeコントロールを削除したいのですが、やり方がわかりません。


Lineshapeコントロールは以下のソースのように配置しています。
配置したコントロール名がわかれば削除できそうなのですが、コントロール名の取得の方法がわかりません。

配置したLineshapeコントロールを削除する方法があれば上記の方法以外でも構いません。
どなたかアドバイスいただけたら幸いです。

以下ソースです。

Dim canvas As New PowerPacks.ShapeContainer


Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click
Dim win As New LINESHAPE

' Set the form as the parent of the ShapeContainer.
canvas.Parent = Me.PictureBox6

' Set the ShapeContainer as the parent of the LineShape.
win.Parent = canvas


win.BorderWidth = 20
win.BorderColor = Color.LightBlue

win_index = win_index + 1
win.SetIndx(win_index)
win.SetAng(0)
win.Name = "Win" & win_index

win.SetX(Panel1.Width / 2)
win.SetY(Panel1.Height / 2)
win.X1 = win.GetX - 50 * Math.Cos(win.GetAng * Math.PI / 180)
win.Y1 = win.GetY + 50 * Math.Sin(win.GetAng * Math.PI / 180)
win.X2 = win.GetX + 50 * Math.Cos(win.GetAng * Math.PI / 180)
win.Y2 = win.GetY - 50 * Math.Sin(win.GetAng * Math.PI / 180)





'動的にイベントを関連付ける
AddHandler win.MouseDown, AddressOf win_MouseDown
AddHandler win.MouseUp, AddressOf win_MouseUp
AddHandler win.MouseMove, AddressOf win_MouseMove

End Sub

Public Class LINESHAPE
Inherits PowerPacks.LineShape
Dim idx As String
Dim ang As String
Dim p_x As String
Dim p_y As String

Public Sub SetIndx(index As String)
idx = index
End Sub
Public Sub SetAng(angle As String)
ang = angle
End Sub
Public Sub SetX(xx As String)
p_x = xx
End Sub
Public Sub SetY(yy As String)
p_y = yy
End Sub

Public Function GetIndx()
Return idx
End Function
Public Function GetAng()
Return ang
End Function

Public Function GetX()
Return p_x
End Function
Public Function GetY()
Return p_y
End Function


End Class

以上、よろしくお願い致します。

A 回答 (1件)

この質問からはどのコントロールを消すのかはわかりませんでしたが、


コントロール名は分かりそうなので、
ControlsクラスのFindメソッドで検索できると思います。
http://dobon.net/vb/dotnet/control/findcontrolby …

この回答への補足

回答ありがとうございます。

Lineshapeの型はControlではなくPowerPacks.Shapeのようなので、
Findメソッドがうまく使えません。なにかよい方法があればお願いします。


現在配置しているLineshapeコントロールの一覧を表示させるための
ソースを下に貼り付けます。ご参考ください。

Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.DoubleClick

Dim MyControl As PowerPacks.Shape
Dim AllName As String
Dim i As Integer


AllName = "フォームに配置されている全てのコントロール名" & Chr(13)

For Each MyControl In canvas.Shapes
i = i + 1
AllName = AllName & Chr(13) & _
i & ":MyControl.Name = " & MyControl.Name
Next


MsgBox(AllName)


End Sub



また、基本的な質問なのですが、
コントロール名というにはそのコントロール
(今回の場合はPowerPacks.Shapeになるのですが、)
のNameプロバティと同じもの。という理解でよろしいでしょうか?

よろしくお願いします。

補足日時:2013/07/19 09:47
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!