简体   繁体   English

使用自动调整图片框/组框vb.net时出错

[英]Error when using auto resize picturebox/groupbox vb.net

Hi I am getting an error when I load my program from the exe file but not when I start from visual studio. 嗨,我从exe文件加载程序时出现错误,而从Visual Studio启动时却没有错误。

The error I receive is 我收到的错误是

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

at MoveResizeControl.controlHandler.mControl_Resize(Object sender, EventArgs e) in C:\\Users\\AJ\\Documents\\Movable_Re217400212010\\MoveResizeControl\\controlHandler.vb:line 211 在C:\\ Users \\ AJ \\ Documents \\ Movable_Re217400212010 \\ MoveResizeControl \\ controlHandler.vb:MoveResizeControl.controlHandler.mControl_Resize(Object sender,EventArgs e)中

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

at System.Windows.Forms.Control.UpdateBounds() at System.Windows.Forms.Control.WmWindowPosChanged(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.GroupBox.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam 在System.Windows.Forms.Control.WmWindowPosChanged(Message&m)在System.Windows.Forms.Control.WndProc(Message&m)在System.Windows.Forms.Group.WndProc (Message&m)在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam

I know my problem is in this bit of code 我知道我的问题在于这段代码

    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

I need to check for null before commencing and am having a problem. 我需要在开始之前检查null并遇到问题。

It's possible that the timer tick event is executed before initialization is complete. 计时器滴答事件可能在初始化完成之前执行。 Try leaving the timers disabled, then enable them in the form "shown" event. 尝试禁用计时器,然后以“显示”事件的形式启用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM