WithEventsで配列やハッシュを使おうとするとエラーがおきます
Friend WithEvents Button(0) As System.Windows.Forms.Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.Load
MsgBox("新しいボタン")
Me.Button(0) = New System.Windows.Forms.Button
Me.SuspendLayout()
Me.Button(0).Location = New System.Drawing.Point(0, 0)
Me.Button(0).Name = "Button0"
Me.Button(0).Size = New System.Drawing.Size(80, 32)
Me.Button(0).TabIndex = 0
Me.Button(0).Text = "Button0"
Me.Controls.Add(Me.Button0)
End Sub
のようにしたいのですがどうしたらよいでしょうか?
WithEventsについて調べましたか?
> Friend WithEvents Button(0) As System.Windows.Forms.Button
Buttonが配列型なので使えないだけだと思うのですが…
※AddHandlerなるものを発見…
どうしてもオブジェクトを配列などで使いたいのですが
やっぱり無理でしょうか?
AddHandler Button(0).Click, AddressOf Button_click
じゃあだめですか。
AddHandlerを使ったらできるようになりました。
ガッさんのおかげで無事解決しました。
まことにありがとうございました。
すみません
我龍院忠太さんもありがとうございました。
こういうのを書きました
Friend Button(1000) As System.Windows.Forms.Button
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
MsgBox("新しいボタン")
Me.Button(0) = New System.Windows.Forms.Button
Me.SuspendLayout()
Me.Button(0).Location = New System.Drawing.Point(0, 0)
Me.Button(0).Name = "Button0"
Me.Button(0).Size = New System.Drawing.Size(64, 32)
Me.Button(0).TabIndex = 0
Me.Button(0).Text = "New"
Me.Controls.Add(Me.Button(0))
AddHandler Button(ii).Click, AddressOf BTN_CLICK
End Sub
Private Sub BTN_CLICK(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("hello, word!")
End Sub
本当にありがとうございました
>AddHandler Button(ii).Click, AddressOf BTN_CLICK
AddHandler Button(0).Click, AddressOf BTN_CLICK
>MsgBox("hello, word!")
#MsgBox("Hello, World!")の方が良いかも、なんとなく。orz
ツイート | ![]() |