私はVBの新機能です。次のコードでこのエラーが発生します。PictureBoxのMouseDownエラー:Handles句にWithEventsが必要です
Handles句には、包含型またはその基本型のいずれかで定義されたWithEvents変数が必要です。 (BC30506)基本的に
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
私は他の質問を読んでいると、まさにこの理由を把握することができないよう、このスニペット
Private Offset As Size 'used to hold the distance of the mouse`s X and Y position to the picturebox Left and Top postition
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Dim ptc As Point = Me.PointToClient(MousePosition) 'get the mouse position in client coordinates
Offset.Width = ptc.X - PictureBox1.Left 'get the width distance of the mouse X position to the picturebox`s Left position
Offset.Height = ptc.Y - PictureBox1.Top 'get the height distance of the mouse Y position to the picturebox`s Top position
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Then 'make sure the left mouse button is down first
Dim ptc As Point = Me.PointToClient(MousePosition) 'get the mouse position in client coordinates
PictureBox1.Left = ptc.X - Offset.Width 'set the Left position of picturebox to the mouse position - the offset width distance
PictureBox1.Top = ptc.Y - Offset.Height 'set the Top position of picturebox to the mouse position - the offset height distance
End If
End Sub
ごとにマウスダウンイベントにピクチャボックスオブジェクトを移動しようとしていますコードが機能していません。
あなたはコードでPictureBoxを作成しましたか? – Plutonix