-2

In Windows Form, Created Multiple panel's(Panel's contains multiple panel's) and each panel's having different background colors,When run the application ,if expand the form means,the Panles getting shake for a few milli seconds and then reaches its required place.Can't fix it. Could you give me idea to solve this..

Thanks

Saravanan

User6667769
  • 745
  • 1
  • 7
  • 25

2 Answers2

1

In your form's resize event, when you resize your panels, add Layout.Suspend() at the beginning and Layout.Resume() at the end. This should stop the shaking.

The shaking is basically because when form size changes, and the child panels receive the trigger to resize themselves, they all create panic and chaos amongst themselves trying to adjust themselves in the given Layout. When you suspend the layout, the actual live chaos is not displayed on the UI and the shakes go away, but the result is not something you might have had in mind. However, try it out first then decide.

athar13
  • 382
  • 1
  • 8
  • First of all thanks for your reply, I created event for my form private void myform_Resize(object sender, EventArgs e) { this.SuspendLayout(); this.ResumeLayout(); } But the same shake happens again..I did the way is correct or not? – User6667769 Mar 24 '17 at 09:41
  • As well as i didn't add any controls at the run time – User6667769 Mar 24 '17 at 09:47
  • Ummm...I think not. Where are you doing the panel resizing, if it is not in the Form_Resize()? Have you docked them to the form? – athar13 Mar 24 '17 at 09:47
  • private void panel__Resize(object sender, EventArgs e) { this.SuspendLayout(); this.ResumeLayout(); } I did this for my all panels also..i didn't docked them.i just applied some anchors – User6667769 Mar 24 '17 at 09:51
  • 1
    Oh I see. Then you cannot handle the shakes because it is done automatically. Change the form's DoubleBuffer property value to true and check – athar13 Mar 24 '17 at 09:59
  • I set the DoubleBuffer Property value to true .and run the application and expand the form...i m sorry to say this , the same thing happened. – User6667769 Mar 24 '17 at 10:12
  • Hey Friend,Thanks for your guidance,I got my result. – User6667769 Mar 27 '17 at 05:41
  • It would be better if you explained your solution so others would benefit mate :-) – athar13 Mar 28 '17 at 01:29
  • i put my answer in result area and I explained the code too.these above code prevents flickers while expanding our form. – User6667769 Mar 28 '17 at 04:40
0

Fixed it.Use this code to avoid shakes while expanding windows form. Its exactly called as Flicker.

Use the NameSpace:

Using System.Runtime.InteropServices

Create a class and write the code:

internal static class NativeWinAPI
{
    internal static readonly int GWL_EXSTYLE = -20;
    internal static readonly int WS_EX_COMPOSITED = 0x02000000;

    [DllImport("user32")]
    internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32")]
    internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int     dwNewLong);
}    

and add the code in your form constructor:

public MyForm()
{
    InitializeComponent();

    int style = NativeWinAPI.GetWindowLong(this.Handle,NativeWinAPI.GWL_EXSTYLE);
    style |= NativeWinAPI.WS_EX_COMPOSITED;
    NativeWinAPI.SetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE, style);
}

I got this result from: Avoid Flickering in Windows Forms?

Community
  • 1
  • 1
User6667769
  • 745
  • 1
  • 7
  • 25