【发布时间】:2017-09-02 13:45:35
【问题描述】:
我正在使用眼动仪在表单上显示眼动。运动一直在闪烁,所以我发现我可以使用 BufferedGraphics 一切正常,除了当眼球运动开始时,它会将表单从原始颜色变为黑色。这是代码。希望有人可以提供帮助!
private void button2_Click(object sender, EventArgs e)
{
var host = new Host();
var gazeStream = host.Streams.CreateGazePointDataStream();
gazeStream.GazePoint((x, y, ts)
=> drawCircle(new PointF((float)x, (float)y)));
}
delegate void SetCallback(PointF point);
private void drawCircle(PointF point)
{
float x = point.X;
float y = point.Y;
if (this.InvokeRequired)
{
SetCallback d = new SetCallback(drawCircle);
this.Invoke(d, new object[] { point });
}
else
{
SolidBrush semiTransBrush = new SolidBrush(Color.Coral);
Pen pen = new Pen(Color.Aquamarine, 2);
BufferedGraphicsContext currentContext;
BufferedGraphics myBuffer;
// Gets a reference to the current BufferedGraphicsContext
currentContext = BufferedGraphicsManager.Current;
// Creates a BufferedGraphics instance associated with Form1, and with
// dimensions the same size as the drawing surface of Form1.
myBuffer = currentContext.Allocate(this.CreateGraphics(),this.DisplayRectangle);
myBuffer.Graphics.DrawEllipse(pen, x, y, 100, 100);
myBuffer.Graphics.FillEllipse(semiTransBrush, x, y, 100, 100);
// Renders the contents of the buffer to the specified drawing surface.
myBuffer.Render(this.CreateGraphics());
myBuffer.Dispose();
}
您可以在图像中看到圆圈出现在控件后面,看起来好像表单消失了?
【问题讨论】:
-
在绘制形状之前尝试
myBuffer.Graphics.Clear(this.BackColor);- 如果表单上没有其他内容 -
我在表单上有单选按钮和标签。控件仍然显示。看起来好像表单的背景已经被移除,而不是颜色只是改变了
-
问题的代码在哪里?显示有关该方法的更多详细信息
-
好的,我添加了更多信息。但我不确定这会有所不同
-
谁能帮忙?????????
标签: c# winforms rendering buffering