0
我在Windows.Forms
的Panel上画图。
当我在这里使用双缓冲时,我只能分配矩形区域。双缓冲非矩形分配
而当我画圆或椭圆时,剩下的空间充满了黑色。
请帮我弄清楚我做错了什么或如何解决这个问题。
在此先感谢! :)
我试过this.DoubleBuffered = true
以防止闪烁。这没有用。
Var p
是面板绘制的东西。
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);
}
}
但如果我想要透明背景色,因为我是用表格的背景图像模式? – 2011-01-14 13:10:20