掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
コントロールの消し方について (ID:142816)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
> しかし WithEvents 変数として管理したいのであれば、 > 先に示した 案1 か 案2 で対応する事になります。 一応、実装例を挙げておきます。 ボタンを押すとラベル増加、そのラベルを右クリックで削除です。 > 案2) WithEvents 変数を持ったクラスをコレクションで管理 http://www.vb-user.net/junk/replySamples/2009.11.10.23.26/CustomLabel.zip > 案1) 必要個数分の WithEvents 変数を予め用意 Option Explicit Private Const Max As Integer = 5 Public WithEvents and_d1 As Label Public WithEvents and_d2 As Label Public WithEvents and_d3 As Label Public WithEvents and_d4 As Label Public WithEvents and_d5 As Label Private Sub Command1_Click() Dim n As Integer Dim lblName As String, lbl As Label For n = 1 To Max lblName = "and_d" & CStr(n) Set lbl = CallByName(Me, lblName, VbGet) If lbl Is Nothing Then Set lbl = Controls.Add("VB.Label", lblName) lbl.Caption = lblName lbl.Move 400, n * 360, 720, 240 lbl.Visible = True CallByName Me, "and_d" & CStr(n), VbSet, lbl Exit Sub End If Next End Sub Private Sub Remove(ByVal Button As MouseButtonConstants, ByVal Index As Integer) If CBool(Button And vbRightButton) Then Dim lblName As String lblName = "and_d" & CStr(Index) Dim lbl As Label Set lbl = CallByName(Me, lblName, VbGet) Controls.Remove lbl CallByName Me, lblName, VbSet, Nothing End If End Sub Private Sub and_d1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Remove Button, 1 End Sub Private Sub and_d2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Remove Button, 2 End Sub Private Sub and_d3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Remove Button, 3 End Sub Private Sub and_d4_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Remove Button, 4 End Sub Private Sub and_d5_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Remove Button, 5 End Sub
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.