Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) mState = 1 'マウスが押されたときの座標を保存 mX = X mY = Y
End Sub Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If mState = 1 Then '押されたときの座標との差分移動 Picture2.Move X - mX + Picture2.Left, Y - mY + Picture2.Top
X1 = Picture1.Width / 4 X2 = X1 + Picture1.Width / 4 X3 = X2 + Picture1.Width / 4 Picture1.Line (X1 - 40, Picture1.Height)-(X1 + 40, Picture1.Height / 4), blue, BF Picture1.Line (X2 - 40, Picture1.Height)-(X2 + 40, Picture1.Height / 4), blue, BF Picture1.Line (X3 - 40, Picture1.Height)-(X3 + 40, Picture1.Height / 4), blue, BF End If Label1.Caption = "Picture1.CurrentX=" & Picture1.CurrentX & "Picture1.CurrentY=" & Picture1.CurrentY Label2.Caption = "Picture1.Height=" & Picture1.Height End Sub Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) mState = 0 End Sub //EOF 以下の写真のイメージでハノイの塔を考えています よろしくお願いします
やってる意味を掴み易くするために
Label3とLabel4を追加してください。
下記部分に簡単に変更してますので
Private Sub Picture2_MouseMove
を書き換えてください。
あくまで簡単にしてるので操作上つらい部分があります(汗
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If mState = 1 Then
'今の位置を持つ
Dim NowTop As Integer
Dim NowLeft As Integer
NowTop = Picture2.Top
NowLeft = Picture2.Left
'Picture1の上との位置判定
If Picture2.Top <= -1 Then
Picture2.Move NowLeft, 0
mState = 0
Exit Sub
End If
'Picture1の左との位置判定
If Picture2.Left <= -1 Then
Picture2.Move 0, NowTop
mState = 0
Exit Sub
End If
'Picture1の下との位置判定
If Picture2.Top >= Picture1.Height - Picture2.Height + 200 Then
Picture2.Move NowLeft, Picture1.Height - Picture2.Height
mState = 0
Exit Sub
End If
'Picture1の右との位置判定
If Picture2.Left >= Picture1.Width - Picture2.Width + 200 Then
Picture2.Move Picture1.Width - Picture2.Width, NowTop
mState = 0
Exit Sub
End If
'押されたときの座標との差分移動
Picture2.Move X - mX + Picture2.Left, Y - mY + Picture2.Top