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. How to slide a panel without flickering

How to slide a panel without flickering

Scheduled Pinned Locked Moved C#
csharpvisual-studiotutorialquestion
7 Posts 3 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.
  • S Offline
    S Offline
    SJ_Phoenix
    wrote on last edited by
    #1

    Hello, I want to slide a panel like f.e. toolbox in Visual Studio. It works fine...as long as there are no further controls on it, then it gets interrupted quite often (I guess because it repaints the controls on it every time) while applying the slide effect which looks ugly... I tried several things, but nothing worked...any ideas or suggestions? thanks. -- modified at 13:48 Saturday 4th March, 2006

    A 2 Replies Last reply
    0
    • S SJ_Phoenix

      Hello, I want to slide a panel like f.e. toolbox in Visual Studio. It works fine...as long as there are no further controls on it, then it gets interrupted quite often (I guess because it repaints the controls on it every time) while applying the slide effect which looks ugly... I tried several things, but nothing worked...any ideas or suggestions? thanks. -- modified at 13:48 Saturday 4th March, 2006

      A Offline
      A Offline
      AFSEKI
      wrote on last edited by
      #2

      Create a custom panel from inherited from Panel class. In constructor after InitializeComponent() function, write: this.SetStyle(ControlStyles.DoubleBuffer,true); this.SetStyle(ControlStyles.AllPaintingInWmPaint,true); this.SetStyle(ControlStyles.UserPaint,true); and then do all the painting by overriding onpaint event of your custom control. That's all. Bluehunter

      S 1 Reply Last reply
      0
      • A AFSEKI

        Create a custom panel from inherited from Panel class. In constructor after InitializeComponent() function, write: this.SetStyle(ControlStyles.DoubleBuffer,true); this.SetStyle(ControlStyles.AllPaintingInWmPaint,true); this.SetStyle(ControlStyles.UserPaint,true); and then do all the painting by overriding onpaint event of your custom control. That's all. Bluehunter

        S Offline
        S Offline
        SJ_Phoenix
        wrote on last edited by
        #3

        thank you for this advice..but this doesn't help because I move the panel by changing its location to achieve the slider effect...so DoubleBuffered doesn't help..(I also tried it already with no effect).

        T 1 Reply Last reply
        0
        • S SJ_Phoenix

          thank you for this advice..but this doesn't help because I move the panel by changing its location to achieve the slider effect...so DoubleBuffered doesn't help..(I also tried it already with no effect).

          T Offline
          T Offline
          Thomas Stockwell
          wrote on last edited by
          #4

          Have you tried handling the WM_PAINT event in the WndProc? If you try using the WndProc you will be able to choose when the control should paint and stop the event from raising when the control should not be painted. Regards, 1tg46 Check out 3D Game Development with Dark Basic Professional [^]programming.

          1 Reply Last reply
          0
          • S SJ_Phoenix

            Hello, I want to slide a panel like f.e. toolbox in Visual Studio. It works fine...as long as there are no further controls on it, then it gets interrupted quite often (I guess because it repaints the controls on it every time) while applying the slide effect which looks ugly... I tried several things, but nothing worked...any ideas or suggestions? thanks. -- modified at 13:48 Saturday 4th March, 2006

            A Offline
            A Offline
            AFSEKI
            wrote on last edited by
            #5

            Hi, I don't know how it did not worked because I'm also a visual component developer and have developed custom panels also which you can move by mouse, expand and collapse vertically and horizontally (with or without animation) and everything works fine. Override WndProc event of your panel where you can find an example in MSDN library under WndProc. Handle the WM_PAINT event in a switch statement which is a value of 0x000F. To prevent repaint of your panel on every pixel move, checkout the location change and make it repaint itself forexample if the change is 2 or 3 pixels... [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] protected override void WndProc(ref Message m) { // Listen for operating system messages. switch (m.Msg) { // The WM_PAINT message occurs when the application // becomes the active application or becomes inactive. case 0x000F: // WM_PAINT // What you should check... // if new location of your panel is NOT different enough // to repaint: // Msg.Result = IntPtr.Zero; // prevents the repaint of your panel // else: // do nothing break; } base.WndProc(ref m); } But my first reply should have helped you, if this does not help either, send me your code. I can have a look at it and may see if you do something wrong by mistake.

            A 1 Reply Last reply
            0
            • A AFSEKI

              Hi, I don't know how it did not worked because I'm also a visual component developer and have developed custom panels also which you can move by mouse, expand and collapse vertically and horizontally (with or without animation) and everything works fine. Override WndProc event of your panel where you can find an example in MSDN library under WndProc. Handle the WM_PAINT event in a switch statement which is a value of 0x000F. To prevent repaint of your panel on every pixel move, checkout the location change and make it repaint itself forexample if the change is 2 or 3 pixels... [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] protected override void WndProc(ref Message m) { // Listen for operating system messages. switch (m.Msg) { // The WM_PAINT message occurs when the application // becomes the active application or becomes inactive. case 0x000F: // WM_PAINT // What you should check... // if new location of your panel is NOT different enough // to repaint: // Msg.Result = IntPtr.Zero; // prevents the repaint of your panel // else: // do nothing break; } base.WndProc(ref m); } But my first reply should have helped you, if this does not help either, send me your code. I can have a look at it and may see if you do something wrong by mistake.

              A Offline
              A Offline
              AFSEKI
              wrote on last edited by
              #6

              Please clear the comments of WM_PAINT message decleration. I have forgotten to change them because I copied the code from MSDN Library example and modified explicitly. WM_PAINT occures nearly %90 of all times, "not only" when the application becomes active or inactive. Hope everything works fine.

              S 1 Reply Last reply
              0
              • A AFSEKI

                Please clear the comments of WM_PAINT message decleration. I have forgotten to change them because I copied the code from MSDN Library example and modified explicitly. WM_PAINT occures nearly %90 of all times, "not only" when the application becomes active or inactive. Hope everything works fine.

                S Offline
                S Offline
                SJ_Phoenix
                wrote on last edited by
                #7

                Thank you for your help..... it's better now...but with controls on it (like some standard buttons) when the panel grows (I mean when it sliders to the right) it still has some problems... here is the code: public partial class LeftSidedSliderPanel : Panel //, IMessageFilter { public static List allPanels = new List(); private int headerWidth = 30; private bool animating = false; private Timer slideEffectTimer; public int HeaderWidth { get { return headerWidth; } set { headerWidth = value; } } public LeftSidedSliderPanel() { InitializeComponent(); allPanels.Add(this); this.Disposed += delegate { allPanels.Remove(this); }; this.DoubleBuffered = true; // Application.AddMessageFilter(this); } public void Stop() { if (this.slideEffectTimer != null) { this.slideEffectTimer.Stop(); } if (hoverTimer != null) { hoverTimer.Stop(); } //preparing for more speed for (int i = 0; i < this.Controls.Count; i++) { this.Controls[i].ResumeLayout(); } animating = false; } private void StartSliding(int targetValue) { if (animating) { return; } this.animating = true; this.SuspendLayout(); //preparing for more speed for (int i = 0; i < this.Controls.Count; i++) { this.Controls[i].SuspendLayout(); } this.slideEffectTimer = new Timer(); this.slideEffectTimer.Interval = 10; int difference = 40;// 40; if (this.Location.X > targetValue + difference) //get smaller { difference = 20; } int tempDifference = difference; this.slideEffectTimer.Tick += delegate { if (difference <= 0) { difference = tempDifference; } if (this.Location.X > targetValue + difference) //get smaller { User32.MoveWindow(t

                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