I have two pictureBoxes & two Panels. On PictureBox1_Click, I want that Panel2 is Fadeout & Panel2 is Fadein. & on vice-versa on PictureBox2_Click.


I write the foll. code-- But with that code form is also fade in & fade out.

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        FormFade("out")
        FormFade("in")
        Me.Panel1.Visible = True
        Me.Panel2.Visible = False
        Me.Opacity = 99
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        FormFade("out")
        FormFade("in")
        Me.Panel2.Visible = True
        Me.Panel1.Visible = False
        Me.Opacity = 99
    End Sub

    Private Sub FormFade(ByVal FType As String)
        Select Case FType
            Case ("in")
                Dim FadeCount As Integer
                For FadeCount = 10 To 90 Step 5
                    Me.Opacity = FadeCount / 100
                    Me.Refresh()
                    Threading.Thread.Sleep(50)
                    System.Windows.Forms.Application.DoEvents()
                Next
            Case ("out")
                Dim FadeCount As Integer
                For FadeCount = 90 To 10 Step -5
                    Me.Opacity = FadeCount / 100
                    Me.Refresh()
                    Threading.Thread.Sleep(50)
                    System.Windows.Forms.Application.DoEvents()
                Next
        End Select
    End Sub

To achieve that only panel is fade in & fade out.I write the foll. code,But its not working,Plz help out where i m wrong-

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        Dim FadeCount As Integer
        Dim Opacity1 As Double
        Dim Opacity2 As Double
        Dim FadeCount1 As Integer

        For FadeCount = 90 To 10 Step -5
            Opacity1 = FadeCount / 100
            Panel2.BackColor = Color.FromArgb(Opacity1)
            Panel1.Refresh()
            Threading.Thread.Sleep(50)
            System.Windows.Forms.Application.DoEvents()
        Next

        For FadeCount1 = 10 To 90 Step 5
            Opacity2 = FadeCount1 / 100
            Panel1.BackColor = Color.FromArgb(Opacity2)
            Panel2.Refresh()
            Threading.Thread.Sleep(50)
        Next

        Me.Panel1.Visible = True
        Me.Panel2.Visible = False
    End Sub