簡體   English   中英

使用自動調整圖片框/組框vb.net時出錯

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

嗨,我從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)中

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

在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

我知道我的問題在於這段代碼

    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並遇到問題。

計時器滴答事件可能在初始化完成之前執行。 嘗試禁用計時器,然后以“顯示”事件的形式啟用它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM