0

In my custom control file:

namespace myApp {
    public partial class MyStatusBar : Label {

      public MyStatusBar () {
          InitializeComponent ();
          this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
          this.Dock = DockStyle.Bottom;
      }

      protected override void OnPaint (PaintEventArgs pe) {
          base.OnPaint (pe);
          pe.Graphics.DrawRectangle (new Pen (Color.Azure), ClientRectangle);         
      }
    }
}

In my form:

MyStatusBar mStatusBarLabel = new MyStatusBar ();

public MCADDrg() {
     InitializeComponent ();

     this.SetStyle (ControlStyles.OptimizedDoubleBuffer, true);
     this.SetStyle (ControlStyles.AllPaintingInWmPaint, true);
     this.SetStyle (ControlStyles.UserPaint, true);
     this.SetStyle (ControlStyles.SupportsTransparentBackColor, false);
     this.SetStyle (ControlStyles.Opaque, false);
     this.SetStyle (ControlStyles.OptimizedDoubleBuffer, true);
     this.SetStyle (ControlStyles.ResizeRedraw, true);

     splitContainer1.Panel2.Controls.Add (mStatusBarLabel);   
     splitContainer1.Panel2.MouseMove += Panel2_MouseMove;
}

void Panel2_MouseMove (object sender, MouseEventArgs e) {
    if( splitContainer1.Panel2.ClientRectangle.Contains(e.Location))
        mStatusBarLabel.Text = "X = " + e.X + " Y = " + e.Y;
    }
}

enter image description here

How can I get rid of this? I tried some other posts answer. But didn't work for me. Assume that (in fact) I'm a newbie.

Naveen Kumar V
  • 2,559
  • 2
  • 29
  • 43
  • The basic solution to "my control flickers" is to double-buffer the rendering. There are many existing questions and answers on Stack Overflow on the topic already, including the marked one. If you find yourself with a _specific_ question involving implementation of double-buffered rendering, and which is not already answered (which you've determined by performing a thorough search on the site), please post a new question, including [a good, _minimal_, _complete_ code example](https://stackoverflow.com/help/mcve) showing clearly what you've tried, explaining what specific problem you have. – Peter Duniho Oct 30 '15 at 06:43
  • @PeterDuniho I should have included the things tried from other posts question. This 'Double buffer' didn't solve my issue. – Naveen Kumar V Oct 30 '15 at 06:54
  • protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED return cp; } } This code in form helped me. :) – Naveen Kumar V Oct 30 '15 at 06:58

0 Answers0