こんにちは、冬の猫と申します。 VB.NET2010にて、教えて頂きたく投稿します。 現在作成中のプログラムの簡易仕様は、 (1)フォーム上に複数のボタンが配置されている。 (2)ボタンの上にマウスを載ったタイミングで0.5秒カウントする。 (3)0.5秒のカウントが終わるまでマウスがボタンの上にあれば、ボタンのサイズを大きくする。 (4)ボタンの上からマウスがなくなれば、ボタンを元のサイズに戻す。 という形になっているのですが(3)の実装がうまくいきません。 以下にソースコードを貼り付けます。 Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'ボタンのサイズ共通化処理 Dim o As Control For Each o In Me.Controls If o.GetType Is GetType(Button) Then o.Size = New Size(50, 50) End If Next For Each ctl As Control In Me.Controls If TypeOf ctl Is Button Then AddHandler CType(ctl, Button).MouseEnter, AddressOf Button_MouseEnter End If Next For Each ctl2 As Control In Me.Controls If TypeOf ctl2 Is Button Then AddHandler CType(ctl2, Button).MouseLeave, AddressOf Button_MouseLeave End If Next End Sub Private Sub Button_MouseEnter(sender As System.Object, e As System.EventArgs) 'マウスが乗った時 'ボタンの取得 Dim btn As Button = CType(sender, Button) btn.Size = New size(100, 100) End Sub Private Sub Button_MouseLeave(sender As System.Object, e As System.EventArgs) 'マウスが離れた時 'ボタンの取得 Dim btn As Button = CType(sender, Button) btn.Size = New Size(50, 50) End Sub End Class 細かい処理は割愛していますが、大まかにはこの様な処理を作成しました。 インターネットからのコピーアンドペーストもあるので、少し不細工な形になっています。 これに、タイマーイベントを実装したいのですが ボタンの上にマウスが乗った際に、タイマーをスタートさせて 該当するボタンのオブジェクトを取得できず困っております。 ご教授のほど、よろしくお願いします。
↧