0

我导入了 Visual Studio 2012 不支持的字体。代码正在运行,但是当标签的边界和移动图片框的边界接触时出现问题,标签出现错误(请参阅链接,因为我不能发布图像呢)。

http://img196.imageshack.us/img196/4562/ybzy.jpg

当 2 个对象已使用 Me.Close() 关闭并通过 Form.Show() 再次打开,然后 2 个对象触及彼此的边界时,会发生错误。对于想知道为什么我需要关闭和重新打开表单的人,我需要它来完成我的简单游戏的下一个级别。

注意:在关闭第一个表单之前,我将打开另一个表单,该表单内将有许多代码,在我关闭该表单之前,我将再次打开第一个表单。

注意:inviders.TTF 在我的 Debug 文件夹中。

模块代码:

Imports System.Drawing.Text

Module Module1
    Public shoLevel As Short = 1

    Public Function custFont(data As String, ByVal size As Single, ByVal style As FontStyle) As Font
         Dim customFfont As Font
         Dim pfc = New PrivateFontCollection()
         pfc.AddFontFile(Application.StartupPath & data)
         customFont = New Font(pfc.Families(0), size, FontStyle.Regular)
         Return customFont
    End Function
End Module

具有标签和移动图片框的第一个表单(显示关卡)的代码。

注意:我没有显示控制图片框另一个方向的其他计时器。让我们假设通过直线向上移动,图片框会碰到标签。

Public Class Form1

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
         Label1.Font = custFont("\invaders.TTF", 20, FontStyle.Regular)
         Label1.Text = "L E V E L " & shoLevel
         Label1.Location = New Point((Me.Width - lblLevel.Width) / 2, (Me.Height - lblLevel.Height) / 2)
    timer1.Start()
     End Sub

     Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Tick
         Static x as integer = 0
         picturebox1.Top -= 2
         x+=1
         If x >= 100 Then
              timer1.Stop()
              Form2.Show()
              Me.Close()
         End If
     End Sub
End Class

具有标签和移动图片框的第二种形式(主游戏)的代码。

注意:错误也发生在这里。

 Public Class Form2
     Dim blnNextLevel as Boolean = False

     Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
         Label1.Font = custFont("\invaders.TTF", 20, FontStyle.Regular)
         Label1.Text = "L E V E L " & shoLevel

        '*insert lines of codes here*'

         timer1.Start()
     End Sub

     '*timer that has a validation if it is ready for the next level*'
     Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Tick
         '*insert lines of codes here*'
         '*Assuming that the blnNextLevel is now True*'
         If blnNextLevel = True Then
              shoLevel += 1
              Form1.Show()
              Me.Close()
         End IF
     End Sub

     '*Insert codes for other objects like timers for the moving pictureboxes*'
 End Class
4

0 回答 0