运行

时间:2018-02-14 18:00:13

标签: vb.net

当我在visual studio.net中放置标签时遇到问题,然后当我运行应用程序时,标签位置发生了变化。

如下图所示:

1在运行前显示在设计模式中。 2显示了我运行应用程序的时间。

我正在使用这些代码行来防止用户更改表单大小:

    Me.FormBorderStyle = FormBorderStyle.FixedSingle
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.CenterToScreen()

完成的代码:

Public Class game2
    Private Sub game2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LblPoint.Text = GlobalVariables.points
        Me.FormBorderStyle = FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.CenterToScreen()

        lchair.Parent = Background
        lclock.Parent = Background
        lclothe1.Parent = Background
        lclothe3.Parent = Background
        lcloth2.Parent = Background
        ldrower.Parent = Background
        llamp.Parent = Background


        ' Start the timer.
        lblTimeLeft.Text = (GlobalVariables.m & ":" & GlobalVariables.s)
        game.Timer1.Start()
    End Sub
end class

1.  in the designing mode. 2. in the running mode.

enter image description here

1 个答案:

答案 0 :(得分:0)

解决方案由@Jimi在上面的评论中发布。 我只是创建一个函数,并在添加标签时调用它。

Private Sub setLabels(labelName As Label)
        labelName.Parent = Background
        labelName.Location = New Point(labelName.Location.X - Background.Left, labelName.Location.Y - Background.Top)

    End Sub