如果一个图片框接触另一个图片框,表格的背景会发生变化,我该怎么做呢? [英] How do I make it so if one picture box touches another picture box the form's back ground changes?

查看:78
本文介绍了如果一个图片框接触另一个图片框,表格的背景会发生变化,我该怎么做呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我是视觉基础的初学者

我想知道是否有办法让它如此如果一个图片框触及另一个图片框

I was wondering if there was a way to make it so that if one picture box touches another picture box

四分之一的背景会发生变化吗?

the background of the fourm changes?

推荐答案

您好

这里有一些代码来说明2图片之间的简单碰撞Boxes。

Here is some code to illustrate a simple collision between 2 Picture Boxes.

.IntersectsWith就是你想要的 - 也许吧。只需将Timer1添加到新Form1并使用此代码替换默认代码即可试用。

The .IntersectsWith would be what you are looking for - perhaps. Just add a Timer1 to a new Form1 and replace default code with this code to try it out.

' Form1 with Timer1
Option Strict On
Option Explicit On
Public Class Form1
  Dim pb1, pb2 As New PictureBox
  Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown

    With pb1
      .Size = New Size(50, 50)
      .Location = New Point(10, 10)
      .BackColor = Color.Black
    End With
    With pb2
      .Size = New Size(50, 50)
      .Location = New Point(100, 25)
      .BackColor = Color.Blue
    End With
    Controls.AddRange({pb1, pb2})
    With Timer1
      .Interval = 50
      .Enabled = True
    End With
  End Sub
  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    pb1.Location = New Point(pb1.Location.X + 1, pb1.Location.Y)

    If pb1.Bounds.IntersectsWith(pb2.Bounds) Then
      pb1.BackColor = Color.Red
    Else
      pb1.BackColor = Color.Black
    End If
  End Sub
End Class


这篇关于如果一个图片框接触另一个图片框,表格的背景会发生变化,我该怎么做呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆