0


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.

Shaiwal Tripathi
  • 497
  • 4
  • 16
  • 1
    Note: 1. The form has a DoubleBuffered property, no need to do more wrt to the form. 2. Doublebuffering is not passed to the nested controls. 3. __We see nothing of the code that might cause flicker. What do you do?__ Draw? Scroll? Load data? – TaW Mar 20 '19 at 10:58
  • Why are you doing all of that invoking when `this.DoubleBuffered = true;` would do the job? – Enigmativity Mar 20 '19 at 10:59
  • @TaW - What does "no need to do more wrt the form" mean? – Enigmativity Mar 20 '19 at 10:59
  • @Enig: The same as your comment. But if he draws onto the Panel or some other control he will need doublebuffering there as well. Not sure why he does it this way; I would either use a subclass or a proper [function](https://stackoverflow.com/questions/44185298/update-datagridview-very-frequently/44188565#44188565) to turn it on or off.. – TaW Mar 20 '19 at 11:02
  • @TaW 1) I have tried `this.DoubleBuffered = true;` But it didn't work. So I tried this. 2) So what should I do if doublebuffering doesn't passed through nested controls. ? 3) What code you want ? – Shaiwal Tripathi Mar 20 '19 at 11:08
  • 1
    We need the code that causes the flicker. And: Each control that shows flicker must get doublebuffered individually. Doublebuffering the parents/containers is useless. – TaW Mar 20 '19 at 11:10
  • @TaW Check my update for Code. – Shaiwal Tripathi Mar 20 '19 at 11:15
  • @TaW I have double buffered to each control. But still the same issue. I can't understand why It's flickering on minimize and maximize only. – Shaiwal Tripathi Mar 20 '19 at 11:23

0 Answers0