图形在绘制之前翻译内容

时间:2015-01-11 09:47:19

标签: c# winforms graphics gdi+ draw

我遇到了以下问题:我正在绘制一张高分辨率的实时图表。我在主循环中获取浮点值,并且我想将此值绘制到现有实例结构(它是表单的图形实例)。
要做到这一点,我必须将整个图形内容在x方向上翻译1,以绘制我的新观点。问题是,翻译似乎会影响新点,而不影响现有内容

代码(缩写)如下所示:

float oldval = 0;
Graphics gr = this.CreateGraphics();

public void IndependentThread(...)
{
    float h = (float)this.Height;
    Pen p = Pens.Pink;

    while (condition_to_exit_loop)
    {
        float current = 0;

        this.Invoke(new MethodInvoker(() => current = getVal())); //<-- funtion witch fetches the current value

        gr.TranslateTransform(1, 0); //<--- I want to translate the existing content - not the new one
        gr.DrawLine(p, 0, h * current, 1, h * oldval);

        oldval = current;
    }
}

0 个答案:

没有答案
相关问题