Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Transparency issues

C# Transparency issues

Scheduled Pinned Locked Moved C#
csharpperformancehelpquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adam Durity
    wrote on last edited by
    #1

    Hey, So i'm working on this form that fades in and out depending on when it's active or not. Essentially it's a for loop that just iterates the opacity value of the form up to the desired value. for(float f = 0.0f; f < 0.5f; f += 0.05f) { this.Opacity = f; } The problem is, this is really slow and flickery. I'm hoping to get something around the speed of the fading in and out of Winamp 5, if you all have seen that. something along the lines of 100-500ms, or even < 1s, but still have it look smoothe and not flicker so much. Any suggestions? I mean will DirectDraw do what I want? Thanks. -- Adam "If you can't beat your computer in chess, try kickboxing"

    H B 2 Replies Last reply
    0
    • A Adam Durity

      Hey, So i'm working on this form that fades in and out depending on when it's active or not. Essentially it's a for loop that just iterates the opacity value of the form up to the desired value. for(float f = 0.0f; f < 0.5f; f += 0.05f) { this.Opacity = f; } The problem is, this is really slow and flickery. I'm hoping to get something around the speed of the fading in and out of Winamp 5, if you all have seen that. something along the lines of 100-500ms, or even < 1s, but still have it look smoothe and not flicker so much. Any suggestions? I mean will DirectDraw do what I want? Thanks. -- Adam "If you can't beat your computer in chess, try kickboxing"

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Through a Thread.Sleep in the loop taking into account the duration of the effect and the number of iterations required.

      Microsoft MVP, Visual C# My Articles

      A 1 Reply Last reply
      0
      • H Heath Stewart

        Through a Thread.Sleep in the loop taking into account the duration of the effect and the number of iterations required.

        Microsoft MVP, Visual C# My Articles

        A Offline
        A Offline
        Adam Durity
        wrote on last edited by
        #3

        Wouldn't that make the fade longer? -- Adam "If you can't beat your computer in chess, try kickboxing"

        H L 2 Replies Last reply
        0
        • A Adam Durity

          Wouldn't that make the fade longer? -- Adam "If you can't beat your computer in chess, try kickboxing"

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Right now your loop doesn't take any time into account and depends upon the speed of your machine. You need to control the opacity. Right now, the loop would probably run so fast that it would appear to jump from 0.0 to 0.5 (or whatever it was) immediately. You need to control the duration. When you're talking about 10 ms or so, the naked eye typically won't catch it. Just think of movies you watch. In the use, it's only 29.97 fps (NTSC) where in other parts of the world it's like 30 fps (PAL) or something. Do you notice each individual frame? if you need 10 iterations and use Thread.Sleep(50) to sleep for 50 ms between each iteration, your fade effect will take only 500 ms like you mentioned a desire for in your first post.

          Microsoft MVP, Visual C# My Articles

          L 1 Reply Last reply
          0
          • A Adam Durity

            Wouldn't that make the fade longer? -- Adam "If you can't beat your computer in chess, try kickboxing"

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            It would, but that would make the fade more 'realistic'. Also call Application.DoEvents() after each call, so the UI seem to 'respond'. top secret xacc-ide 0.0.1

            1 Reply Last reply
            0
            • H Heath Stewart

              Right now your loop doesn't take any time into account and depends upon the speed of your machine. You need to control the opacity. Right now, the loop would probably run so fast that it would appear to jump from 0.0 to 0.5 (or whatever it was) immediately. You need to control the duration. When you're talking about 10 ms or so, the naked eye typically won't catch it. Just think of movies you watch. In the use, it's only 29.97 fps (NTSC) where in other parts of the world it's like 30 fps (PAL) or something. Do you notice each individual frame? if you need 10 iterations and use Thread.Sleep(50) to sleep for 50 ms between each iteration, your fade effect will take only 500 ms like you mentioned a desire for in your first post.

              Microsoft MVP, Visual C# My Articles

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              Heath Stewart wrote: Just think of movies you watch. In the use, it's only 29.97 fps (NTSC) where in other parts of the world it's like 30 fps (PAL) or something. Movies are usually 24fps, while PAL is 25fps. Animations like Simpsons are tradionally 15fps, but I suspect that was before CG and computer animation came into play. top secret xacc-ide 0.0.1

              H 1 Reply Last reply
              0
              • L leppie

                Heath Stewart wrote: Just think of movies you watch. In the use, it's only 29.97 fps (NTSC) where in other parts of the world it's like 30 fps (PAL) or something. Movies are usually 24fps, while PAL is 25fps. Animations like Simpsons are tradionally 15fps, but I suspect that was before CG and computer animation came into play. top secret xacc-ide 0.0.1

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                Actually, you had one right (PAL, and thanks for correcting me on that) but the 29.97 fps I am sure of. See http://www.microcinema.com/index/ntsc[^], for example.

                Microsoft MVP, Visual C# My Articles

                L 1 Reply Last reply
                0
                • H Heath Stewart

                  Actually, you had one right (PAL, and thanks for correcting me on that) but the 29.97 fps I am sure of. See http://www.microcinema.com/index/ntsc[^], for example.

                  Microsoft MVP, Visual C# My Articles

                  L Offline
                  L Offline
                  leppie
                  wrote on last edited by
                  #8

                  Heath Stewart wrote: you had one right Sorry, with movies, I meant film as in the theater, thats 24fps, NTSC (never the same color) is 29.97fps :) top secret xacc-ide 0.0.1

                  1 Reply Last reply
                  0
                  • A Adam Durity

                    Hey, So i'm working on this form that fades in and out depending on when it's active or not. Essentially it's a for loop that just iterates the opacity value of the form up to the desired value. for(float f = 0.0f; f < 0.5f; f += 0.05f) { this.Opacity = f; } The problem is, this is really slow and flickery. I'm hoping to get something around the speed of the fading in and out of Winamp 5, if you all have seen that. something along the lines of 100-500ms, or even < 1s, but still have it look smoothe and not flicker so much. Any suggestions? I mean will DirectDraw do what I want? Thanks. -- Adam "If you can't beat your computer in chess, try kickboxing"

                    B Offline
                    B Offline
                    bneacetp
                    wrote on last edited by
                    #9

                    You could handle this using a timer in your form. Handle its elapsed event and make gradual changes with each tick, stopping the counter when the opacity reached its min or max. I have done this and it produces no flicker. Happy Programming and God Bless! Internet::WWW::CodeProject::bneacetp

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups