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