Hi I have a c# usercontrol that I override OnPaint
method.
In my OnPaint Method I have the following code:
// Draw the new button.
protected override void OnPaint(PaintEventArgs e) {
Color btnColor = this.ButtonColor;
if (!this.ButtonEnabled) {
btnColor = Color.LightGray;
}
Bitmap GraphicsImage = new Bitmap(24, 24, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics.FromImage(GraphicsImage).Clear(btnColor);
Graphics graphics = e.Graphics;
SolidBrush myBrush = new SolidBrush(btnColor);
Pen myPen = new Pen(btnColor);
// Draw the button in the form of a circle
graphics.DrawEllipse(myPen, 0, 0, 40, 40);
graphics.FillEllipse(myBrush, new Rectangle(0, 0, 40, 40));
if (!DesignMode) {
Image iconImg = null;
switch (this.ButtonImage) {
case CircleButtonImage.ArrowDown:
iconImg = POS.Framework.Utility.Common.GetResourceImage("arrowdown_16.png");
break;
case CircleButtonImage.ArrowUp:
iconImg = POS.Framework.Utility.Common.GetResourceImage("arrowup_16.png");
break;
case CircleButtonImage.Cross:
iconImg = POS.Framework.Utility.Common.GetResourceImage("close_16.png");
break;
case CircleButtonImage.Plus:
iconImg = POS.Framework.Utility.Common.GetResourceImage("plus_16.png");
break;
}
graphics = Graphics.FromImage(GraphicsImage);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graphics.DrawImage(iconImg, 5, 5);
this.CreateGraphics().DrawImageUnscaled(GraphicsImage, new Point(7, 6));
}
myBrush.Dispose();
myPen.Dispose();
}
This works well but in order to avoid flickering I added to my constructor:
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
Then the png
image is not showing any more.
Without doublebufferd:
With doublebuffered:
Any clue on how to fix this. I want to avoid flickering but need the image to be rendered.