Panel Opacity

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Yogesh Sharma
    New Member
    • Mar 2008
    • 40

    Panel Opacity

    I have two pictureBoxes & two Panels. On PictureBox1_Cli ck, I want that Panel2 is Fadeout & Panel2 is Fadein. & on vice-versa on PictureBox2_Cli ck.


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

    Code:
     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-

    Code:
    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
    Last edited by kenobewan; Nov 3 '08, 12:30 PM. Reason: Please use code tags
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I'm not a VB person, but...

    I don't think changing the background color is going to get you what you want.
    You want to change the opacity of the object, not the backcolor.

    Take a look at the properties of a Form. Use Visual Studio's Intellesense.

    Start entering these two lines (or their VB equivelent)...

    Code:
    Form bob = new Form();
    bob.
    As soon as you hit the point you should get a popup with all the properties you can choose for Form bob. You'll see that you can choose opacity.

    Now do the same thing with a Panel.

    Code:
    Panel bob = new Panel();
    bob.
    Notice this time there is no opacity option. A panel is always fully opaque regardless of its background color.

    Comment

    Working...