自己做的Usercontrol,里面的内容是画的,有刷新问题,每次刷新的时候,屏幕都闪的厉害,有什么办法能让它不闪??

解决方案 »

  1.   

    在UserControl的构造函数中添加如下的一句话:
    this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
      

  2.   

    是用Graphics的DrawIcon和DrawString等方法来画出来的,内容很多,图片的话,太占资源,而且不好控制,随时变化的。
      

  3.   

    参考这么绘制方法'绘制窗体左、右、底部边框
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
            Dim bmp As New Bitmap(e.ClipRectangle.Width, Me.Height)
            Dim g As Graphics = Graphics.FromImage(bmp)        '左边框
            g.DrawImage(LeftEdge_Middle_Bitmap, 0, 0, BorderWidth, Me.Bounds.Height)
            g.DrawImage(LeftEdge_Top_Bitmap, 0, 0, BorderWidth, CaptionHeight)
            g.DrawImageLeftEdge_Bottom_Bitmap, 0, Me.Bounds.Height - LeftEdge_Bottom_Bitmap.Height, BorderWidth, LeftEdge_Bottom_Bitmap.Height)
            '下边框
            g.DrawImage(BottomEdge_Middle_Bitmap, 0, Me.Bounds.Height - BorderWidth, Me.Bounds.Width, BorderWidth)
            g.DrawImage(BottomEdge_Left_Bitmap, 0, Me.Bounds.Height - BorderWidth, BottomEdge_Left_Bitmap.Width, BorderWidth)
            g.DrawImage(BottomEdge_Right_Bitmap, Me.Bounds.Width - BottomEdge_Right_Bitmap.Width, Me.Bounds.Height - BorderWidth, BottomEdge_Right_Bitmap.Width, BorderWidth)
            '右边框
            g.DrawImage(RightEdge_Middle_Bitmap, Me.Bounds.Width - BorderWidth, 0, BorderWidth, Me.Bounds.Height)
            g.DrawImage(RightEdge_Top_Bitmap, Me.Bounds.Width - BorderWidth, 0, BorderWidth, CaptionHeight)
            g.DrawImage(RightEdge_Bottom_Bitmap, Me.Bounds.Width - BorderWidth, Me.Bounds.Height - RightEdge_Bottom_Bitmap.Height, BorderWidth, RightEdge_Bottom_Bitmap.Height)        e.Graphics.DrawImage(bmp, 0, 0)'窗体刷新就这一句进行绘制
            g.Dispose() : bmp = Nothing
        End Sub
      

  4.   

    参考游戏制作的做法,,,,,,,,用DX SDK做它,哇卡卡
      

  5.   

    hbxtlhx(平民百姓-自已动手,丰衣足食)双缓冲怎么搞??没搞过,不懂,给个例子看看。
      

  6.   

    我这有段代码,楼主参考下:
    public partial class UserControl1 : UserControl
    {
    private Timer timer;
    private Rectangle m_Rect;
    public UserControl1()
    {
    InitializeComponent();
    timer = new Timer();
    m_Rect = new Rectangle(0, 0, 100, 61);
    timer.Interval = 20;
    timer.Enabled = true;
    this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
    timer.Tick += new EventHandler(timer_Tick);
    } bool v = true;
    bool h = true;
    void timer_Tick(object sender, EventArgs e)
    {
    if (h)
    {
    this.m_Rect.X++;
    }
    else
    {
    this.m_Rect.X--;
    }
    if (v)
    {
    this.m_Rect.Y++;
    }
    else
    {
    this.m_Rect.Y--;
    }
    if (this.m_Rect.Right > this.ClientRectangle.Right)
    {
    h=false;
    }
    else if (this.m_Rect.X < this.ClientRectangle.X)
    {
    h = true;
    }
    if (this.m_Rect.Bottom > this.ClientRectangle.Bottom)
    {
    v = false;
    }
    else if (this.m_Rect.Y < this.ClientRectangle.Y)
    {
    v = true;
    }
    this.Invalidate();
    }
    protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e);
    e.Graphics.FillRectangle(SystemBrushes.Desktop, this.m_Rect);
    }
    }
      

  7.   

    OnPaint里面只是BitBlt一个位图绘图都在一个Bitmap上操作这样会快一点
      

  8.   

    这个问题确实不好解决,尤其是自制控件中有pictruebox加载的图片信息,如果更换界面,首先得将背景置为透明。然后图片自己捕捉屏幕界面的颜色一块一块的刷。至今未找到好的解决办法,为此,还专门更换了界面显示的方式(用的是另外一组图形控件)。你可以试一下visual graph的图形显示平台,类似与组态。