我有两个图片盒,另一个不能触及它的右边和左边。有可能吗?
答案 0 :(得分:0)
您可以检查图片框是否覆盖了Location.X
和Location.Y
属性。
要将一个图片框翻转到顶部或底部,请使用SetBounds(x,y,width,height)
方法。
示例:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim xw = PictureBox1.Location.X + PictureBox1.Width
Dim x2w = PictureBox2.Location.X + PictureBox2.Width
If PictureBox2.Location.X <= xw AndAlso x2w < xw Then 'PictureBox2 touches right side of PictureBox1 => flip to bottom'
movePictureBox(PictureBox1, PictureBox2, PictureBox1.Height + 5)
ElseIf PictureBox2.Location.X <= xw AndAlso x2w >= xw Then 'PB2 touches left side of PB1 => flip to top'
movePictureBox(PictureBox1, PictureBox2, -PictureBox2.Height - 5)
End If
End Sub
Private Sub movePictureBox(picFrom As PictureBox, picToMove As PictureBox, yOffset As Integer)
'Set new location for picToMove according to picFrom.X and picFrom.Y + offset'
picToMove.SetBounds(picFrom.Location.X, picFrom.Location.Y + yOffset, picToMove.Width, picToMove.Height)
End Sub