I am trying to avoid form's flickering in my windows application (MDI) but unable to avoid it completely.
What I have tried...
1) I have put this code in my form.cs
protected override CreateParams CreateParams
{
get
{
var cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
2) Turned on double buffered for both Form and Panel
typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, pnlNotification, new object[] { true });
typeof(Form).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, this, new object[] { true });
Main Problem
My above codes are working great, but when I minimize my application and maximize it again flickering starts again.
Structure Of My Form
I have used a parent panel in every form and put all controls inside that panel.
I am calling form from MDI Parent like this
if (menuStrip1.Enabled == true)
{
frmProductSale ProductSale = new frmProductSale(this);
ProductSale.MdiParent = this;
ProductSale.Show();
}
And Child Form Code..
Constructor...
public frmProductSale(frmHome Hm)
{
InitializeComponent();
Home = Hm;
}
Load
private void frmProductSale_Load(object sender, EventArgs e)
{
UserName = ((Label)Home.Controls.Find("lblUserName", true).SingleOrDefault()).Text;
BrowseStatus = (Label)Home.Controls.Find("lblBrowseStatus", true).SingleOrDefault();
ResetStatus = (Label)Home.Controls.Find("lblResetStatus", true).SingleOrDefault();
SaveUpdateStatus = (Label)Home.Controls.Find("lblSaveUpdateStatus", true).SingleOrDefault();
RecordSelectionStatus = (Label)Home.Controls.Find("lblRecordSelectionStatus", true).SingleOrDefault();
QuantityStatus = (Label)Home.Controls.Find("lblQuantityStatus", true).SingleOrDefault();
ImportantMethods.CreateEvents(pnlProductSale, this, "Product Sale");
FillValues(this, UserName);
txtPatientName__L.Focus();
}
Thank You.