D'improvviso tutti gli strumenti di un form non funzionano più

di il
9 risposte

D'improvviso tutti gli strumenti di un form non funzionano più

Spero di non aver sbagliato sezione del Forum.
Sto sviluppando una app in VB.NET con vs2022 con 2 form ed un modulo che si interfaccia con arduino, per il treno elettrico di uh amico.

il form 1 serve solo a seriale ad aprire la porta seriale di comunicazione con arduino.
Nel secondo form sono rappresentati binari di stazione e si possono inviare i comandi degli scambi e delle sezioni di binario.

Oggi pomeriggio ho avviato vs2022, caricato il file .sln e quindi ho lanciato il debug ... non mi ha dato nessun errore, il primo form si è caricato normalmente , si è caricato normalmente anche il form 2 ,,,, ma gli strumenti non davano nessun segno di vita !!!

Cosa diavolo ho fatto di sbagliato ???

9 Risposte

  • Re: D'improvviso tutti gli strumenti di un form non funzionano più

    Naturalmente se non mostri almeno una parte del tuo codice l'indovinello è alquanto difficile da risolvere. Hai forse rinominato i controlli (quelli che chiami "strumenti") e/o il form ? In questi casi può  accadere che le routine di gestione degli eventi perdano la clausola Handles... 

  • Re: D'improvviso tutti gli strumenti di un form non funzionano più

    ciao grumpi provo a mettere il codice ,,, ma sono un migliaio di righe ,,,, vabbe', lo metto
    Public Class Form2
    
        Private Sub Button1_Click(sender As Object, e As EventArgs)
            Timer2.Enabled = True
            Dim openform As New Form1
            openform.Show()
        End Sub
        Private Sub inizializza_Click_1(sender As Object, e As EventArgs) Handles inizializza.Click
    
            T1S.Visible = True
    
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
    
            surface.DrawLine(pen3, 115, 620, 165, 567)
            surface.DrawLine(pen3, 225, 567, 280, 507)
            Bin0a.BackColor = Color.DarkSlateGray
            Bin0b.BackColor = Color.DarkSlateGray
    
            Bin1.BackColor = Color.DarkSlateGray
            Bin1a.BackColor = Color.White
            surface.DrawLine(pen1, 787, 511, 831, 460)
    
            surface.DrawLine(pen3, 647, 570, 700, 504)
            Bin2.BackColor = Color.DarkSlateGray
    
            Bin3.BackColor = Color.DarkSlateGray
            Bin3a.BackColor = Color.DarkSlateGray
    
            surface.DrawLine(pen3, 530, 659, 567, 615)
            Bin4.BackColor = Color.DarkSlateGray
            surface.DrawLine(pen3, 693, 617, 731, 662)
            Bin4a.BackColor = Color.DarkSlateGray
    
            surface.DrawLine(pen3, 595, 520, 495, 415)
            Bin0n.BackColor = Color.DarkSlateGray
    
            Bin1n.BackColor = Color.DarkSlateGray
    
            Bin3n.BackColor = Color.DarkSlateGray
    
            surface.DrawLine(pen3, 439, 377, 493, 416)
            Bin4n.BackColor = Color.DarkSlateGray
    
            Bin5.BackColor = Color.DarkSlateGray
    
            Bin6.BackColor = Color.DarkSlateGray
            surface.DrawLine(pen3, 843, 445, 882, 399)
    
            B1Denerg.Visible = False
            B1Energ.Visible = True
            B1Energ.Enabled = True
            B1aEnerg.Visible = False
            B2Denerg.Visible = False
            B3Denerg.Visible = False
            B3Energ.Visible = True
            T2S.Visible = False
    
        End Sub
    
        Function Disegna()
    
            BlockB0()
            BlockB1()
            BlockB1a()
            BlockB2()
            BlockB3()
            BlockB3a()
            BlockB4()
            BlockB4a()
            BlockB0N()
            BlockB1N()
            BlockB3N()
            BlockB4N()
            BlockB5()
            BlockB6()
    
            ' BlockBS1()
            ' BlockBS2()
            ' BlockBS3()
            ' BlockBS4()
    
            ' BlockBL1V()
            ' BlockBL2V()
            ' BlockBL3V()
            ' BlockBL4V()
    
            '  BlockBL1E()
            '  BlockBL2E()
            '  BlockBL3E()
            '  BlockBL4E()
        End Function
    
    
        ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   SCAMBI          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        Private Sub S1Wr_Click(sender As Object, e As EventArgs) Handles S1Wr.Click
            S1Wr.Visible = False
            S1Wr.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<0,0>")
            S1Wd.Visible = True
            S1Wd.Enabled = True
    
    
        End Sub
    
        Private Sub S1Wd_Click(sender As Object, e As EventArgs) Handles S1Wd.Click
    
            S1Wr.Visible = True
            S1Wr.Enabled = True
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<0,1>")                    '0
            S1Wd.Visible = False
            S1Wd.Enabled = False
    
    
        End Sub
        Private Sub S2Wr_Click(sender As Object, e As EventArgs) Handles S2Wr.Click
            S2Wr.Visible = False
            S2Wr.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<1,0>")
            S2Wd.Visible = True
            S2Wd.Enabled = True
            S3Wr.Visible = False
            S3Wr.Enabled = False
            S3Wd.Visible = True
            S3Wd.Enabled = True
        End Sub
        Private Sub S2Wd_Click(sender As Object, e As EventArgs) Handles S2Wd.Click
            S2Wr.Visible = True
            S2Wr.Enabled = True
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<1,1>")
            S2Wd.Visible = False
            S2Wd.Enabled = False
            S3Wd.Enabled = False
            S3Wr.Visible = True
            S3Wr.Enabled = True
        End Sub
        Private Sub S3Wr_Click(sender As Object, e As EventArgs) Handles S3Wr.Click
            S3Wr.Visible = False
            S3Wr.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<1,0>")
            S2Wd.Visible = True
            S2Wd.Enabled = True
            S2Wr.Visible = False
            S2Wr.Enabled = False
            S3Wd.Visible = True
            S3Wd.Enabled = True
        End Sub
        Private Sub S3Wd_Click(sender As Object, e As EventArgs) Handles S3Wd.Click
    
            S2Wr.Visible = True
            S2Wr.Enabled = True
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<1,1>")
            S2Wd.Visible = False
            S2Wd.Enabled = False
            S3Wd.Visible = False
            S3Wd.Enabled = False
            S3Wr.Visible = True
            S3Wr.Enabled = True
        End Sub
    
        Private Sub S1Nd_Click(sender As Object, e As EventArgs) Handles S1Nd.Click
            S1Nd.Visible = False
            S1Nd.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<3,1>")
            S1Nr.Visible = True
            S1Nr.Enabled = True
        End Sub
    
        Private Sub S1Nr_Click(sender As Object, e As EventArgs) Handles S1Nr.Click
            S1Nr.Visible = False
            S1Nr.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<3,0>")
            S1Nd.Visible = True
            S1Nd.Enabled = True
        End Sub
    
        Private Sub S3Nr_Click(sender As Object, e As EventArgs) Handles S3Nr.Click
            S3Nr.Visible = False
            S3Nr.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<4,0>")
            S3Nd.Visible = True
            S3Nd.Enabled = True
        End Sub
        Private Sub S3Nd_Click(sender As Object, e As EventArgs) Handles S3Nd.Click
            S3Nd.Visible = False
            S3Nd.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<4,1>")
            S3Nr.Visible = True
            S3Nr.Enabled = True
        End Sub
    
        Private Sub S1Er_Click(sender As Object, e As EventArgs) Handles S1Er.Click
            S1Er.Visible = False
            S1Er.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<5,0>")
            S1Ed.Visible = True
            S1Ed.Enabled = True
        End Sub
    
        Private Sub S1Ed_Click_1(sender As Object, e As EventArgs) Handles S1Ed.Click
            S1Ed.Visible = False
            S1Ed.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<5,1>")
            S1Er.Visible = True
            S1Er.Enabled = True
    
        End Sub
    
        Private Sub S2Er_Click(sender As Object, e As EventArgs) Handles S2Er.Click
            S2Er.Visible = False
            S2Er.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<6,1>")
            S2Ed.Visible = True
            S2Ed.Enabled = True
        End Sub
        Private Sub S2Ed_Click(sender As Object, e As EventArgs) Handles S2Ed.Click
            S2Ed.Visible = False
            S2Ed.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<6,0>")
            S2Er.Visible = True
            S2Er.Enabled = True
        End Sub
        Private Sub S3Er_Click(sender As Object, e As EventArgs) Handles S3Er.Click
            S3Er.Visible = False
            S3Er.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<7,0>")
            S3Ed.Visible = True
            S3Ed.Enabled = True
        End Sub
    
        Private Sub S3Ed_Click(sender As Object, e As EventArgs) Handles S3Ed.Click
            S3Ed.Visible = False
            S3Ed.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<7,1>")
            S3Er.Visible = True
            S3Er.Enabled = True
    
        End Sub
        Private Sub S4Er_Click(sender As Object, e As EventArgs) Handles S4Er.Click
            S4Er.Visible = False
            S4Er.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<8,0>")
            S4Ed.Visible = True
            S4Ed.Enabled = True
        End Sub
    
        Private Sub S4Ed_Click(sender As Object, e As EventArgs) Handles S4Ed.Click
            S4Ed.Enabled = False
            S4Ed.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<8,1>")
            S4Er.Visible = True
            S4Er.Enabled = True
        End Sub
    
        Private Sub S5Er_Click(sender As Object, e As EventArgs) Handles S5Er.Click
            S5Er.Enabled = False
            S5Er.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<9,0>")
            S5Ed.Visible = True
            S5Ed.Enabled = True
        End Sub
        Private Sub S5Ed_Click(sender As Object, e As EventArgs) Handles S5Ed.Click
            S5Ed.Enabled = False
            S5Ed.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<9,1>")
            S5Er.Visible = True
            S5Er.Enabled = True
        End Sub
        Private Sub S6Er_Click(sender As Object, e As EventArgs) Handles S6Er.Click
            S6Er.Enabled = False
            S6Er.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<10,1>")
            S6Ed.Visible = True
            S6Ed.Enabled = True
        End Sub
    
        Private Sub S6Ed_Click(sender As Object, e As EventArgs) Handles S6Ed.Click
            S6Ed.Enabled = False
            S6Ed.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<10,0>")
            S6Er.Visible = True
            S6Er.Enabled = True
        End Sub
    
    
    
    
        Private Sub S8Er_Click(sender As Object, e As EventArgs) Handles S8Er.Click
            S8Er.Enabled = False
            S8Er.Visible = False
            S9Er.Visible = False
            S9Er.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<12,0>")
            S8Ed.Visible = True
            S8Ed.Enabled = True
            S9Ed.Visible = True
            S9Ed.Enabled = True
        End Sub
    
        Private Sub S8Ed_Click(sender As Object, e As EventArgs) Handles S8Ed.Click
            S8Ed.Enabled = False
            S8Ed.Visible = False
            S9Ed.Visible = False
            S9Ed.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<12,1>")
            S8Er.Visible = True
            S8Er.Enabled = True
            S9Er.Visible = True
            S9Er.Enabled = True
    
        End Sub
    
        Private Sub S9Er_Click(sender As Object, e As EventArgs) Handles S9Er.Click
            S8Er.Enabled = False
            S8Er.Visible = False
            S9Er.Visible = False
            S9Er.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<12,0>")
            S8Ed.Visible = True
            S8Ed.Enabled = True
            S9Ed.Visible = True
            S9Ed.Enabled = True
    
        End Sub
    
        Private Sub S9Ed_Click(sender As Object, e As EventArgs) Handles S9Ed.Click
            S8Ed.Enabled = False
            S8Ed.Visible = False
            S9Ed.Visible = False
            S9Ed.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<12,1>")
            S8Er.Visible = True
            S8Er.Enabled = True
            S9Er.Visible = True
            S9Er.Enabled = True
        End Sub
    
        Private Sub S7Er_Click(sender As Object, e As EventArgs) Handles S7Er.Click
            S7Er.Enabled = False
            S7Er.Visible = False
            S10Er.Enabled = False
            S10Er.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<11,0>")
            S7Ed.Visible = True
            S7Ed.Enabled = True
            S10Ed.Visible = True
            S10Ed.Enabled = True
        End Sub
    
        Private Sub S7Ed_Click(sender As Object, e As EventArgs)
            S10Ed.Visible = False
            S10Ed.Enabled = False
            S7Ed.Visible = False
            S7Ed.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<11,1>")
            S10Er.Visible = True
            S10Er.Enabled = True
            S7Er.Visible = True
            S7Er.Enabled = True
        End Sub
        Private Sub S10Er_Click(sender As Object, e As EventArgs) Handles S10Er.Click
            S10Er.Enabled = False
            S10Er.Visible = False
            S7Er.Visible = False
            S7Er.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<11,0>")
            S10Ed.Visible = True
            S10Ed.Enabled = True
            S7Ed.Visible = True
            S7Ed.Enabled = True
        End Sub
        Private Sub S10Ed_Click(sender As Object, e As EventArgs) Handles S10Ed.Click
            S10Ed.Visible = False
            S10Ed.Enabled = False
            S7Ed.Visible = False
            S7Ed.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<11,1>")
            S10Er.Visible = True
            S10Er.Enabled = True
            S7Er.Visible = True
            S7Er.Enabled = True
    
        End Sub
    
    
        Private Sub SAr_Click(sender As Object, e As EventArgs) Handles SAr.Click
            SAr.Enabled = False
            SAr.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<15,1>")
            SAd.Visible = True
            SAd.Enabled = True
        End Sub
    
        Private Sub SAd_Click(sender As Object, e As EventArgs) Handles SAd.Click
            SAd.Enabled = False
            SAd.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<15,0>")
            SAr.Visible = True
            SAr.Enabled = True
        End Sub
        Private Sub SBr_Click(sender As Object, e As EventArgs) Handles SBr.Click
            SBr.Enabled = False
            SBr.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<13,1>")
            SBd.Visible = True
            SBd.Enabled = True
        End Sub
    
        Private Sub SBd_Click(sender As Object, e As EventArgs) Handles SBd.Click
            SBd.Enabled = False
            SBd.Visible = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<13,0>")
            SBr.Visible = True
            SBr.Enabled = True
        End Sub
    
        '=====================  FINE SCAMBI  =====================================
    
        '                                  TRAFI
        Private Sub Trafo1ELE_Click(sender As Object, e As EventArgs) Handles Trafo1ELE.Click
            Trafo1ELE.Visible = False
            Trafo1ELE.Enabled = False
            Trafo2ELE.Visible = True
            Trafo2ELE.Visible = True
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<55,0>")
            '   Disegna()
        End Sub
    
        Private Sub Trafo2ELE_Click(sender As Object, e As EventArgs) Handles Trafo2ELE.Click
            Trafo2ELE.Visible = False
            Trafo2ELE.Enabled = False
            Trafo1ELE.Visible = True
            Trafo1ELE.Visible = True
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<55,1>")
            ' Disegna()
        End Sub
    
        Private Sub Trafo1VAP_Click(sender As Object, e As EventArgs) Handles Trafo1VAP.Click
            Trafo1VAP.Visible = False
            Trafo1VAP.Enabled = False
            Trafo2VAP.Visible = True
            Trafo2VAP.Visible = True
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<55,0>")
            Disegna()
        End Sub
    
        Private Sub Trafo2VAP_Click(sender As Object, e As EventArgs) Handles Trafo2VAP.Click
            Trafo2VAP.Visible = False
            Trafo2VAP.Enabled = False
            Trafo1VAP.Visible = True
            Trafo1VAP.Visible = True
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<55,0>")
            Disegna()
        End Sub
    
    
    
    
        '====================================================        BLOCCHI           =========00=================================
        Function BlockB0()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                surface.DrawLine(pen1, 115, 620, 165, 567)
                surface.DrawLine(pen1, 225, 567, 280, 507)
                Bin0a.BackColor = Color.White
                Bin0b.BackColor = Color.White
            End If
    
            If (T2S.Visible = True) Then
                surface.DrawLine(pen2, 115, 620, 165, 567)
                surface.DrawLine(pen2, 225, 567, 280, 507)
                Bin0a.BackColor = Color.Yellow
                Bin0b.BackColor = Color.Yellow
            End If
            If (B0Denerg.Visible = True) Then
                surface.DrawLine(pen3, 115, 620, 165, 567)
                surface.DrawLine(pen3, 225, 567, 280, 507)
                Bin0a.BackColor = Color.DarkSlateGray
                Bin0b.BackColor = Color.DarkSlateGray
            End If
    
        End Function
    
        Function BlockB1()
            If (T1S.Visible = True) Then
    
                Bin1.BackColor = Color.White
    
            End If
    
            If (T2S.Visible = True) Then
    
                Bin1.BackColor = Color.Yellow
    
            End If
            If (B1Denerg.Visible = True) Then
    
                Bin1.BackColor = Color.DarkSlateGray
    
            End If
    
        End Function
        Function BlockB1a()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                Bin1a.BackColor = Color.White
                surface.DrawLine(pen1, 787, 511, 831, 460)
            End If
            If (T2S.Visible = True) Then
                Bin1a.BackColor = Color.Yellow
                surface.DrawLine(pen2, 787, 511, 831, 460)
            End If
            If (B1aDenerg.Visible = True) Then
                Bin1a.BackColor = Color.DarkSlateGray
                surface.DrawLine(pen3, 787, 511, 831, 460)
            End If
    
        End Function
        Function BlockB2()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                surface.DrawLine(pen1, 647, 570, 700, 504)
                Bin2.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                surface.DrawLine(pen2, 647, 570, 700, 504)
                Bin2.BackColor = Color.Yellow
            End If
            If (B2Energ.Visible = True) Then
                surface.DrawLine(pen3, 647, 570, 700, 504)
                Bin2.BackColor = Color.DarkSlateGray
            End If
        End Function
    
        Function BlockB3()
            If (T1S.Visible = True) Then
                Bin3.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                Bin3.BackColor = Color.Yellow
            End If
            If (B3Denerg.Visible = True) Then
    
                Bin3.BackColor = Color.DarkSlateGray
            End If
    
        End Function
    
        Function BlockB3a()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                Bin3a.BackColor = Color.White
                ' surface.DrawLine(pen1, 530, 660, 595, 610)
            End If
            If (T2S.Visible = True) Then
                Bin3a.BackColor = Color.Yellow
            End If
            If (B3aDenerg.Visible = True) Then
                Bin3a.BackColor = Color.DarkSlateGray
            End If
        End Function
    
        Function BlockB4()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                surface.DrawLine(pen1, 530, 659, 567, 615)
                Bin4.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                surface.DrawLine(pen2, 530, 659, 567, 615)
                Bin4.BackColor = Color.Yellow
            End If
            If (B4Denerg.Visible = True) Then
                surface.DrawLine(pen3, 530, 659, 567, 615)
                Bin4.BackColor = Color.DarkSlateGray
            End If
        End Function
    
        Function BlockB4a()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                surface.DrawLine(pen1, 693, 617, 731, 662)
                Bin4a.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                surface.DrawLine(pen2, 693, 617, 731, 662)
                Bin4a.BackColor = Color.Yellow
            End If
            If (B4aDenerg.Visible = True) Then
                surface.DrawLine(pen3, 693, 617, 731, 662)
                Bin4a.BackColor = Color.DarkSlateGray
            End If
        End Function
    
    
    
        Function BlockB5()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                surface.DrawLine(pen2, 830, 445, 890, 345)
                Bin5.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                surface.DrawLine(pen2, 839, 445, 914, 346)
                Bin5.BackColor = Color.Yellow
            End If
            If (B5Energ.Visible = True) Then
                surface.DrawLine(pen2, 839, 445, 914, 395)
                Bin5.BackColor = Color.DarkSlateGray
            End If
    
        End Function
    
    
    
        Function BlockB6()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                surface.DrawLine(pen1, 843, 445, 882, 399)
                Bin6.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                surface.DrawLine(pen2, 843, 445, 882, 399)
                Bin6.BackColor = Color.Yellow
            End If
            If (B6Energ.Visible = True) Then
                surface.DrawLine(pen3, 843, 445, 882, 399)
                Bin6.BackColor = Color.DarkSlateGray
            End If
    
        End Function
    
    
    
        Function BlockB0N()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                surface.DrawLine(pen1, 595, 520, 495, 415)
                Bin0n.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                surface.DrawLine(pen2, 595, 520, 495, 415)
                Bin0n.BackColor = Color.Yellow
            End If
            If (B0nDenerg.Visible = True) Then
                surface.DrawLine(pen3, 595, 520, 495, 415)
                Bin0n.BackColor = Color.DarkSlateGray
            End If
        End Function
    
        Function BlockB1N()
            If (T1S.Visible = True) Then
                Bin1n.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                Bin1n.BackColor = Color.Yellow
            End If
            If (B1nDenerg.Visible = True) Then
                Bin1n.BackColor = Color.DarkSlateGray
            End If
    
        End Function
    
        Function BlockB3N()
            If (T1S.Visible = True) Then
                Bin3n.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                Bin3n.BackColor = Color.Yellow
            End If
            If (B3nDenerg.Visible = True) Then
                Bin3n.BackColor = Color.DarkSlateGray
            End If
        End Function
    
        Function BlockB4N()
            Dim surface As Drawing.Graphics = CreateGraphics()
            Dim pen1 As Pen = New Pen(Color.White, 7)
            Dim pen2 As Pen = New Pen(Color.Yellow, 7)
            Dim pen3 As Pen = New Pen(Color.DarkSlateGray, 7)
            If (T1S.Visible = True) Then
                surface.DrawLine(pen1, 439, 377, 493, 416)
                Bin4n.BackColor = Color.White
            End If
            If (T2S.Visible = True) Then
                surface.DrawLine(pen2, 439, 377, 493, 416)
                Bin4n.BackColor = Color.Yellow
            End If
            If (B4nDenerg.Visible = True) Then
                surface.DrawLine(pen3, 439, 377, 493, 416)
                Bin4n.BackColor = Color.DarkSlateGray
            End If
        End Function
    
        Private Sub T1S_Click(sender As Object, e As EventArgs) Handles T1S.Click
            T1S.Visible = False
            T1S.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<54,0>")
            T2S.Visible = True
            T2S.Enabled = True
            Disegna()
        End Sub
    
        Private Sub T2S_Click(sender As Object, e As EventArgs) Handles T2S.Click
            T2S.Visible = False
            T2S.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<54,1>")
            T1S.Visible = True
            T1S.Enabled = True
            Disegna()
        End Sub
    
        Private Sub B0Energ_Click(sender As Object, e As EventArgs) Handles B0Energ.Click
            B0Energ.Visible = False
            B0Energ.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<922,0>")
            B0Denerg.Visible = True
            B0Denerg.Enabled = True
            BlockB0()
        End Sub
    
        Private Sub B0Denerg_Click(sender As Object, e As EventArgs) Handles B0Denerg.Click
            B0Denerg.Visible = False
            B0Denerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<922,1>")
            B0Energ.Visible = True
            B0Energ.Enabled = True
            BlockB0()
        End Sub
    
        Private Sub B1Energ_Click(sender As Object, e As EventArgs) Handles B1Energ.Click
            B1Energ.Visible = False
            B1Energ.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<923,0>")
            B1Denerg.Visible = True
            B1Denerg.Enabled = True
            BlockB1()
        End Sub
        Private Sub B1Denerg_Click(sender As Object, e As EventArgs) Handles B1Denerg.Click
            B1Denerg.Visible = False
            B1Denerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<923,1>")
            B1Energ.Visible = True
            B1Energ.Enabled = True
            BlockB1()
        End Sub
        Private Sub B1aEnerg_Click(sender As Object, e As EventArgs) Handles B1aDenerg.Click
            Me.B1aDenerg.Visible = False
            Me.B1aDenerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<924,1>")
            B1aEnerg.Visible = True
            B1aEnerg.Enabled = True
            BlockB1a()
        End Sub
    
        Private Sub B1aDenerg_Click(sender As Object, e As EventArgs) Handles B1aEnerg.Click
            B1aEnerg.Visible = False
            B1aEnerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<924,0>")
            Me.B1aDenerg.Visible = True
            Me.B1aDenerg.Enabled = True
            BlockB1a()
        End Sub
        Private Sub B2Energ_Click(sender As Object, e As EventArgs) Handles B2Energ.Click
            B2Energ.Visible = False
            B2Energ.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<925,1>")
            B2Denerg.Visible = True
            B2Denerg.Enabled = True
            BlockB2()
        End Sub
        Private Sub B2Denerg_Click(sender As Object, e As EventArgs) Handles B2Denerg.Click
            B2Denerg.Visible = False
            B2Denerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<925,0>")
            B2Energ.Visible = True
            B2Energ.Enabled = True
            BlockB2()
        End Sub
    
    
        Private Sub B3Energ_Click(sender As Object, e As EventArgs) Handles B3Energ.Click
            B3Energ.Visible = False
            B3Energ.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<926,0>")
            B3Denerg.Visible = True
            B3Denerg.Enabled = True
    
            BlockB3()
        End Sub
    
        Private Sub B3Denerg_Click(sender As Object, e As EventArgs) Handles B3Denerg.Click
            B3Denerg.Visible = False
            B3Denerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<926,1>")
            B3Energ.Visible = True
            B3Energ.Enabled = True
            BlockB3()
        End Sub
    
    
        Private Sub B3aEnerg_Click(sender As Object, e As EventArgs) Handles B3aEnerg.Click
            B3aEnerg.Visible = False
            B3aEnerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<927,0>")
            B3aDenerg.Visible = True
            B3aDenerg.Enabled = True
    
            BlockB3a()
        End Sub
    
        Private Sub B3aDenerg_Click(sender As Object, e As EventArgs) Handles B3aDenerg.Click
            B3aDenerg.Visible = False
            B3aDenerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<927,1>")
            B3aEnerg.Visible = True
            B3aEnerg.Enabled = True
    
            BlockB3a()
        End Sub
    
    
        Private Sub Bin4_Click(sender As Object, e As EventArgs) Handles Bin4.Click
            ' T2S.Visible = False
            '  T2S.Enabled = False
            '  My.Computer.Audio.Play("D:\Music\Clack.wav")
            '   Module1.SP.Write("<928,0>")
            '  T1S.Visible = True
            '  T1S.Enabled = True
            ' BlockB4()
    
        End Sub
        Private Sub B4Energ_Click(sender As Object, e As EventArgs) Handles B4Energ.Click
            B4Energ.Visible = False
            B4Energ.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<928,0>")
            B4Denerg.Visible = True
            B4Denerg.Enabled = True
    
            BlockB4()
        End Sub
    
        Private Sub B4Denerg_Click(sender As Object, e As EventArgs) Handles B4Denerg.Click
            B4Denerg.Visible = False
            B4Denerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<928,1>")
            B4Energ.Visible = True
            B4Energ.Enabled = True
            BlockB4()
        End Sub
    
        Private Sub B4aEnerg_Click(sender As Object, e As EventArgs) Handles B4aEnerg.Click
            B4aEnerg.Visible = False
            B4aEnerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<929,0>")
            B4aDenerg.Visible = True
            B4aDenerg.Enabled = True
            BlockB4a()
        End Sub
    
        Private Sub B4aDenerg_Click(sender As Object, e As EventArgs) Handles B4aDenerg.Click
            B4aDenerg.Visible = False
            B4aDenerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<929,1>")
            B4aEnerg.Visible = True
            B4aEnerg.Enabled = True
            B0nEnerg.Enabled = True
            BlockB4a()
        End Sub
    
        Private Sub B6Denerg_Click(sender As Object, e As EventArgs) Handles B6Denerg.Click
            B6Denerg.Visible = False
            B6Denerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B6Energ.Visible = True
            B6Energ.Enabled = True
            BlockB6()
        End Sub
    
        Private Sub B6Energ_Click(sender As Object, e As EventArgs) Handles B6Energ.Click
            B6Energ.Visible = False
            B6Energ.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B6Denerg.Visible = True
            B6Denerg.Enabled = True
            BlockB6()
        End Sub
    
    
        Private Sub B0nDenerg_Click(sender As Object, e As EventArgs) Handles B0nDenerg.Click
            B0nDenerg.Visible = False
            B0nDenerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B0nEnerg.Visible = True
            B0nEnerg.Enabled = True
            BlockB0N()
    
        End Sub
    
        Private Sub B0nEnerg_Click(sender As Object, e As EventArgs) Handles B0nEnerg.Click
            B0nEnerg.Visible = False
            B0nEnerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B0nDenerg.Visible = True
            B0nDenerg.Enabled = True
            BlockB0N()
        End Sub
    
        Private Sub B1nDenerg_Click(sender As Object, e As EventArgs) Handles B1nDenerg.Click
            B1nDenerg.Visible = False
            B1nDenerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B1nEnerg.Visible = True
            B1nEnerg.Enabled = True
            BlockB1N()
        End Sub
        Private Sub B1nEnerg_Click(sender As Object, e As EventArgs) Handles B1nEnerg.Click
            B1nEnerg.Visible = False
            B1nEnerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B1nDenerg.Visible = True
            B1nDenerg.Enabled = True
            BlockB1N()
        End Sub
    
        Private Sub B3nDenerg_Click(sender As Object, e As EventArgs) Handles B3nDenerg.Click
            B3nDenerg.Visible = False
            B3nDenerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B3nEnerg.Visible = True
            B3nEnerg.Enabled = True
            BlockB3N()
        End Sub
        Private Sub B3nEnerg_Click(sender As Object, e As EventArgs) Handles B3nEnerg.Click
            B3nEnerg.Visible = False
            B3nEnerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B3nDenerg.Visible = True
            B3nDenerg.Enabled = True
            BlockB3N()
        End Sub
    
        Private Sub B4nDenerg_Click(sender As Object, e As EventArgs) Handles B4nDenerg.Click
            B4nDenerg.Visible = False
            B4nDenerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B4nEnerg.Visible = True
            B4nEnerg.Enabled = True
            BlockB4N()
        End Sub
    
        Private Sub B4nEnerg_Click(sender As Object, e As EventArgs) Handles B4nEnerg.Click
            B4nEnerg.Visible = False
            B4nEnerg.Enabled = False
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            B4nDenerg.Visible = True
            B4nDenerg.Enabled = True
            BlockB4N()
        End Sub
    
    
        Private Sub S1EVSred_Click(sender As Object, e As EventArgs) Handles S1EVSred.Click
            INBin1daW()
        End Sub
        Function INBin1daW() 'Ingresso Stazione da West Linea Elettrica
            'Uscita stazione da binario1
            If ((S9Er.Visible = True) And (S5Er.Visible = True) And (S2Er.Visible = True) And (S1Er.Visible = True)) Then
                S1EVSgreen.Visible = True
                S1EVSgreen.Enabled = True
                S1EVSred.Visible = False
                S1EVSred.Enabled = False
            End If
            If (SB1Wred.Visible = True) Then
                S1EVIyellow.Visible = True
                S1EVSred.Visible = False
    
            Else
                S1EVIyellow.Visible = False
                S1EVIspento.Visible = True
            End If
            'Uscita Stazione da binario2 
            If ((S9Er.Visible = True) And (S5Er.Visible = True) And (S2Er.Visible = True)) Then
                SB1Wred.Visible = False
                SB1Wred.Enabled = False
                SB1Wgreen.Visible = True
                SB1Wgreen.Enabled = True
                S1EVIyellow.Visible = False
                S1EVIspento.Visible = True
    
    
            End If
    
    
    
        End Function
    
    
        ' Uscita Binario 1 
        Private Sub SB1Wred_Click(sender As Object, e As EventArgs) Handles SB1Wred.Click
    
        End Sub
    
        Private Sub SB1Wgreen_Click(sender As Object, e As EventArgs) Handles SB1Wgreen.Click
            SB1Wred.Visible = True
            SB1Wred.Enabled = True
            SB1Wgreen.Visible = False
            SB1Wgreen.Enabled = False
        End Sub
    
        Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
            If DateTime.Now.Second Mod 2 Then
                Me.PictureBox1.Image = My.Resources.Selettore1
            Else
                Me.PictureBox1.Image = My.Resources.Selettore2
            End If
        End Sub
    
        Private Sub Test3000_Click(sender As Object, e As EventArgs) Handles Test3000.Click
            My.Computer.Audio.Play("D:\Music\Clack.wav")
            Module1.SP.Write("<3000,1>")
    
            Module1.SP.Write("<5000,1>")
    
            Module1.SP.Write("<2000,1>")
        End Sub
    
        Private Sub Trafo2VAP_Click_1(sender As Object, e As EventArgs)
    
        End Sub
    End Class
    
    
    
    
    
    
    
  • Re: D'improvviso tutti gli strumenti di un form non funzionano più

    28/11/2024 - grumpy ha scritto:

    Naturalmente se non mostri almeno una parte del tuo codice l'indovinello è alquanto difficile da risolvere. Hai forse rinominato i controlli (quelli che chiami "strumenti") e/o il form ? In questi casi può  accadere che le routine di gestione degli eventi perdano la clausola Handles... 

    Direi di no, non mi ricordo di aver rinominato i controlli ...

  • Re: D'improvviso tutti gli strumenti di un form non funzionano più

    Sarebbe corretto postare solo una parte del codice significativa, non pretenderai che qualcuno si metta a leggerlo tutto. Comunque, se tu avessi letto per intero la mia risposta, avresti dovuto accorgerti che qui 

       Private Sub Button1_Click(sender As Object, e As EventArgs)

    manca qualcosa. 

  • Re: D'improvviso tutti gli strumenti di un form non funzionano più

    Come per l'ultima volta, sicuro di non aver modificato nulla?

    Come ti ha mostrato grumpy mancano parti di codice. Hai aggiunto tu quel Button1?

    Dato che ti succede più volte, fai un backup di tutto il progetto funzionante prima di una modifica 

  • Re: D'improvviso tutti gli strumenti di un form non funzionano più

    Grazie del suggeerimento Oregon: in effetti con il Parkinson mi capita di fare casino con la tastiera. in qualche modo, comunque, ho  il progetto. 
    Ho aggiunto un terzo form in cui ho copiato i controlli che erano nel form 2, poi ho copiato il contenuto del file form2.vb nel file form3.vb.

    Ciao 

  • Re: D'improvviso tutti gli strumenti di un form non funzionano più

    E cosa c'entra questo ultimo post con il problema?

    Hai risolto o no?

  • Re: D'improvviso tutti gli strumenti di un form non funzionano più

    NON risolto, perche non ho capito cosa è successo, ma aggirato>>: ora fuziona tutto avendo fatto quanto detto nel oos sopra

  • Re: D'improvviso tutti gli strumenti di un form non funzionano più

    Co.e ti era stato detto mancava la parte

    Handles ...

    nella Sub della gestione del Click, probabilmente per un maldestro copia incolla o azione simile

    Devi fare attenzione a cosa fai tu perchè "d'improvviso" non succede nulla a del codicd che funziona.

    Fai i backup

Devi accedere o registrarti per scrivere nel forum
9 risposte