I draw on Panel in Windows.Forms
.
When I use double buffering like here, I can allocate only rectangular area.
And when I draw circle or ellipse remaining space is filled with black color.
Please, help me figure out what I am doing wrong or how to cope with this problem.
Thanks in advance! :)
I tried this.DoubleBuffered = true
to prevent from flicker. It is no use.
Var p
is Panel to draw something on it.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Dr(bool variant)
{
BufferedGraphicsContext currentContext;
BufferedGraphics myBuffer;
currentContext = BufferedGraphicsManager.Current;
myBuffer = currentContext.Allocate(panel1.CreateGraphics(), panel1.DisplayRectangle);
LinearGradientBrush lgb;
if (variant) lgb = new LinearGradientBrush(new Point(0, 0), new Point(500, 500), Color.Red, Color.DarkRed);
else lgb = new LinearGradientBrush(new Point(0, 0), new Point(500, 500), Color.DarkRed, Color.Red);
myBuffer.Graphics.FillEllipse(lgb, 0, 0, 300, 300);
myBuffer.Graphics.DrawString("Lorem ipsum", new Font("calibri", 40), Brushes.White, new PointF(50, 50));
myBuffer.Render();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Dr(true);
}
private void panel1_MouseEnter(object sender, EventArgs e)
{
Dr(false);
}
private void panel1_MouseLeave(object sender, EventArgs e)
{
Dr(true);
}
}