使用自动调整大小picturebox / groupbox vb.net时出错

时间:2014-04-13 20:40:35

标签: vb.net error-handling nullreferenceexception autoresize

嗨我从exe文件加载程序时收到错误,但是当我从visual studio启动时没有收到错误。

我收到的错误是

>System.NullReferenceException: Object reference not set to an instance of an object.
  

在C:\ Users \ AJ \ Documents \ Movable_Re217400212010 \ MoveResizeControl \ controlHandler.vb中的MoveResizeControl.controlHandler.mControl_Resize(Object sender,EventArgs e):第211行

     

在System.Windows.Forms.Control.OnSizeChanged(EventArgs e)    在System.Windows.Forms.Control.UpdateBounds(Int32 x,Int32 y,Int32 width,Int32 height,Int32 clientWidth,Int32 clientHeight)

     System.Windows.Forms.Control.UpdateBounds()上的

  在System.Windows.Forms.Control.WmWindowPosChanged(消息& m)   在System.Windows.Forms.Control.WndProc(消息& m)   在System.Windows.Forms.GroupBox.WndProc(消息& m)   在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam

我知道我的问题在于这段代码

    Private Sub Timer7_Tick(sender As Object, e As EventArgs) Handles Timer7.Tick
    Timer2.Start()
    Timer5.Start()
    Dim i As Integer
    i = 0
    Dim bl1 As Integer
    Dim br1 As Integer
    Dim tl1 As Integer
    Dim tr1 As Integer
    Dim bl14 As Integer
    Dim br14 As Integer
    Dim tl14 As Integer
    Dim tr14 As Integer

    bl1 = bl.Text
    br1 = br.Text
    tl1 = tl.Text
    tr1 = tr.Text

    bl14 = bl4.Text
    br14 = br4.Text
    tl14 = tl4.Text
    tr14 = tr4.Text

    Me.PictureBox1.Height = (i + bl1) - (i + tl1)
    Me.PictureBox1.Width = (i + br1) - (i + tr1)
    Me.GroupBox1.Height = (i + bl14) - (i + tl14)
    Me.GroupBox1.Width = (i + br14) - (i + tr14)

    Me.PictureBox1.Location = New Point(Me.PictureBox1.Location.X + (0 + tr.Text), Me.PictureBox1.Location.Y + (0 + tl.Text))
    Me.GroupBox1.Location = New Point(Me.GroupBox1.Location.X + (0 + tr4.Text), Me.GroupBox1.Location.Y + (0 + tl4.Text))
    Timer7.Stop()
End Sub

我需要在开始之前检查null并遇到问题。

1 个答案:

答案 0 :(得分:0)

在初始化完成之前执行计时器滴答事件是可能的。尝试禁用计时器,然后以#34;显示"的形式启用它们。事件