我在用c#做绘图时,图很大,要绘制很多坐标轴,而且实时性强,每秒钟刷新一次!
用gdi做了一个坐标轴的customcontrol,坐标轴的标尺和间距是不断刷新可调节的,但是在刷新时有明显的闪烁,当出现屏幕保护后在回到桌面看坐标轴时要几秒钟才能刷新完,实时性太差了,请问哪里出现了问题,如何解决,有没有更好的办法或者其他工具?
部分代码如下:
        public void ReDrawCoordinate()
        {
            this.Invalidate();
        }
        public void SetCoordinateFormat(PaintEventArgs e)
        {
            int_ExecuteCount++;
            //datetime_CurrentDateTime = System.DateTime.Now;
            datetime_RunDateTimeValue = datetime_startLocation;
            int int_RunDateTimeReturnValue = 0;
            int_ControlHeight = this.Height;
            int_ControlWidth = this.Width;
            int_RunDateTimeReturnValue = GetCurrentDateTimeValue();
            CoordinateShowCurrentStepLength = 0;
            while ((int_RunDateTimeReturnValue) % int_CoordinateSpaceValue != 0)
            {
                              GetCoordinateDateTimeModeFormat(CoordinateShowDateTimeModeFormat, 1);
                //CoordinateShowCurrentStepLength++;
                int_RunDateTimeReturnValue = GetCurrentDateTimeValue();
            }
            int_temp = 1;
            while (int_temp <= int_numCoordinateCount)
            {
                if (int_temp == 2)
                {
                    str_CoordinateCurrentValue_2 = datetime_startLocation.ToString(CoordinateShowStringFormat_2);
                    str_CoordinatePrevValue_2 = str_CoordinateCurrentValue_2;
                    int_CoordinateCurrentWidthValue_2 = CoordinateShowCurrentStepLength * CoordinateShowKeyStep_1;
                    int_CoordinateCurrentPrevValue_2 = 0;
                }                if (int_temp == 3)
                {
                    str_CoordinateCurrentValue_3 = datetime_startLocation.ToString(CoordinateShowStringFormat_3);
                    str_CoordinatePrevValue_3 = str_CoordinateCurrentValue_3;
                    int_CoordinateCurrentWidthValue_3 = CoordinateShowCurrentStepLength * CoordinateShowKeyStep_1;
                    int_CoordinateCurrentPrevValue_3 = 0;
                }
                int_temp++;
            }
            while (datetime_RunDateTimeValue <= datetime_endLocation)
            {
                int_temp = 1;
                while (int_temp <= int_numCoordinateCount)
                {
                    if (int_temp == 1)
                    {
                        int_RunDateTimeReturnValue = GetCurrentDateTimeValue();
                        if ((int_RunDateTimeReturnValue) % CoordinateJudgeMod_1 == 0)
                        {
                            rectMainCoordinate = new Rectangle((CoordinateShowCurrentStepLength - CoordinateJudgeValue_1) * CoordinateShowKeyStep_1, int_CoordinateScaleTopHeight_1, CoordinateShowKeyStep_1 * 2 * CoordinateJudgeValue_1, int_CoordinateScaleTopHeight);
                            DrawMainCoordinateString(e, datetime_RunDateTimeValue.ToString(CoordinateShowStringFormat_1));
                        }
                    }
                    if (int_temp == 2)
                    {
                        str_CoordinateCurrentValue_2 = datetime_RunDateTimeValue.ToString(CoordinateShowStringFormat_2);
                        if (str_CoordinateCurrentValue_2 != str_CoordinatePrevValue_2)
                        {
                            int_CoordinateCurrentWidthValue_2 = (CoordinateShowCurrentStepLength) * CoordinateShowKeyStep_1;
                            DrawCoordinateScaleLine(2,e);
                            rectMainCoordinate = new Rectangle(int_CoordinateCurrentPrevValue_2, int_CoordinateScaleTopHeight_2, int_CoordinateCurrentWidthValue_2 - int_CoordinateCurrentPrevValue_2, int_CoordinateScaleBottomHeight);
                            DrawMainCoordinateString(e, str_CoordinatePrevValue_2);
                            int_CoordinateCurrentPrevValue_2 = int_CoordinateCurrentWidthValue_2;
                            str_CoordinatePrevValue_2 = str_CoordinateCurrentValue_2;
                        }
                    }                    if (int_temp == 3)
                    {
                        str_CoordinateCurrentValue_3 = datetime_RunDateTimeValue.ToString(CoordinateShowStringFormat_3);
                        if (str_CoordinateCurrentValue_3 != str_CoordinatePrevValue_3)
                        {
                            int_CoordinateCurrentWidthValue_3 = (CoordinateShowCurrentStepLength) * CoordinateShowKeyStep_1;
                            DrawCoordinateScaleLine(3,e);
                            rectMainCoordinate = new Rectangle(int_CoordinateCurrentPrevValue_3, int_CoordinateScaleTopHeight_3, int_CoordinateCurrentWidthValue_3 - int_CoordinateCurrentPrevValue_3, int_CoordinateScaleBottomHeight);
                            DrawMainCoordinateString(e, str_CoordinatePrevValue_3);
                            int_CoordinateCurrentPrevValue_3 = int_CoordinateCurrentWidthValue_3;
                            str_CoordinatePrevValue_3 = str_CoordinateCurrentValue_3;
                        }
                    }                    if (int_temp == 4)
                    {
                        str_CoordinateCurrentValue_4 = datetime_RunDateTimeValue.ToString(CoordinateShowStringFormat_4);
                        if (str_CoordinateCurrentValue_4 != str_CoordinatePrevValue_4)
                        {
                            int_CoordinateCurrentWidthValue_4 = (CoordinateShowCurrentStepLength) * CoordinateShowKeyStep_1;
                            DrawCoordinateScaleLine(4, e);
                            rectMainCoordinate = new Rectangle(int_CoordinateCurrentPrevValue_4, int_CoordinateScaleTopHeight_4, int_CoordinateCurrentWidthValue_4 - int_CoordinateCurrentPrevValue_4, int_CoordinateScaleBottomHeight);
                            DrawMainCoordinateString(e, str_CoordinatePrevValue_4);
                            int_CoordinateCurrentPrevValue_4 = int_CoordinateCurrentWidthValue_4;
                            str_CoordinatePrevValue_4 = str_CoordinateCurrentValue_4;
                        }
                    }                    if (int_temp == 5)
                    {
                        str_CoordinateCurrentValue_5 = datetime_RunDateTimeValue.ToString(CoordinateShowStringFormat_5);
                        if (str_CoordinateCurrentValue_5 != str_CoordinatePrevValue_5)
                        {
                            int_CoordinateCurrentWidthValue_5 = (CoordinateShowCurrentStepLength) * CoordinateShowKeyStep_1;
                            DrawCoordinateScaleLine(5, e);
                            rectMainCoordinate = new Rectangle(int_CoordinateCurrentPrevValue_5, int_CoordinateScaleTopHeight_5, int_CoordinateCurrentWidthValue_5 - int_CoordinateCurrentPrevValue_5, int_CoordinateScaleBottomHeight);
                            DrawMainCoordinateString(e, str_CoordinatePrevValue_5);
                            int_CoordinateCurrentPrevValue_5 = int_CoordinateCurrentWidthValue_5;
                            str_CoordinatePrevValue_5 = str_CoordinateCurrentValue_5;
                        }
                    }
                    int_temp++;
                }                              GetCoordinateDateTimeModeFormat(CoordinateShowDateTimeModeFormat, int_CoordinateSpaceValue);                  CoordinateShowCurrentStepLength += 1;
            }
            if (CoordinateShowCurrentStepLength * CoordinateShowKeyStep_1 >= 32767)
            {
                err_LabelCaption.Visible = true;
            }
            else
            {
                err_LabelCaption.Visible = false ;
            }
            int_temp = 1;
            while (int_temp <= int_numCoordinateCount)
            {
                if (int_temp == 2)
                {
                    int_CoordinateCurrentWidthValue_2 = (CoordinateShowCurrentStepLength) * CoordinateShowKeyStep_1;
                    rectMainCoordinate = new Rectangle(int_CoordinateCurrentPrevValue_2, int_CoordinateScaleTopHeight_2, int_CoordinateCurrentWidthValue_2 - int_CoordinateCurrentPrevValue_2, int_CoordinateScaleBottomHeight);
                    DrawMainCoordinateString(e, str_CoordinatePrevValue_2);
                }
                if (int_temp == 3)
                {
                    int_CoordinateCurrentWidthValue_3 = (CoordinateShowCurrentStepLength) * CoordinateShowKeyStep_1;
                    rectMainCoordinate = new Rectangle(int_CoordinateCurrentPrevValue_3, int_CoordinateScaleTopHeight_3, int_CoordinateCurrentWidthValue_3 - int_CoordinateCurrentPrevValue_3, int_CoordinateScaleBottomHeight);
                    DrawMainCoordinateString(e, str_CoordinatePrevValue_3);
                }
                if (int_temp == 4)
                {
                    int_CoordinateCurrentWidthValue_4 = (CoordinateShowCurrentStepLength) * CoordinateShowKeyStep_1;
                    rectMainCoordinate = new Rectangle(int_CoordinateCurrentPrevValue_4, int_CoordinateScaleTopHeight_4, int_CoordinateCurrentWidthValue_4 - int_CoordinateCurrentPrevValue_4, int_CoordinateScaleBottomHeight);
                    DrawMainCoordinateString(e, str_CoordinatePrevValue_4);
                }
                if (int_temp == 5)
                {
                    int_CoordinateCurrentWidthValue_5 = (CoordinateShowCurrentStepLength) * CoordinateShowKeyStep_1;
                    rectMainCoordinate = new Rectangle(int_CoordinateCurrentPrevValue_5, int_CoordinateScaleTopHeight_5, int_CoordinateCurrentWidthValue_5 - int_CoordinateCurrentPrevValue_5, int_CoordinateScaleBottomHeight);
                    DrawMainCoordinateString(e, str_CoordinatePrevValue_5);
                }
                int_temp++;
            }
            int_ControlMaxWidth = (CoordinateShowCurrentStepLength) * CoordinateShowKeyStep_1;
        }

解决方案 »

  1.   

    好像就差一条,开双缓冲,this.DoubleBuffered = true;
      

  2.   

    不知道你做的是不是和我的那个类似,看看http://topic.csdn.net/u/20110407/18/f6897786-6106-4f7e-9e1d-e6f99713512f.html
    这个资源你可以看看,都是画图的http://community.csdn.net/
      

  3.   

    我是在一个控件里套了两个子绘图控件,在顶层控件this.DoubleBuffered = true;,一点作用都没有,该怎么办?
      

  4.   

    当启用双缓冲时,所有绘制操作首先呈现到内存缓冲区,而不是屏幕上的绘图图面。所有绘制操作完成后,内存缓冲区直接复制到与其关联的绘图图面。因为在屏幕上只执行一个图形操作,所以消除了由复杂绘制操作造成的图像闪烁。双缓冲实现代码:
    this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    this.SetStyle(ControlStyles.UserPaint, true);
    this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
      

  5.   

    先试试这些个办法吧,不行的话,使用其他语言(非dotnet类,如:VC、delphi)试试,
    再不行,使用directX吧。
    直接写内存和和显存的,