Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# PictureBox的绘制事件正在导致flicking-我还能在哪里执行此操作?_C#_Winforms_Compact Framework_Windows Mobile 6.5 - Fatal编程技术网

C# PictureBox的绘制事件正在导致flicking-我还能在哪里执行此操作?

C# PictureBox的绘制事件正在导致flicking-我还能在哪里执行此操作?,c#,winforms,compact-framework,windows-mobile-6.5,C#,Winforms,Compact Framework,Windows Mobile 6.5,我使用Psion的SDK在移动设备上提供签名控制。 我想在签名控件(一个picturebox)周围画一个矩形。 我在绘画活动中加入了以下内容,但问题是它会闪烁(当你在图片框中签名时,图片框会不断刷新) 是否有一种方法可以将其放入表单的加载事件中,使其只加载一次? 我知道它需要有PainEventArgs,但我不是很确定 private void scSignature_Paint(object sender, PaintEventArgs e) { e.Graph

我使用Psion的SDK在移动设备上提供签名控制。 我想在签名控件(一个picturebox)周围画一个矩形。 我在绘画活动中加入了以下内容,但问题是它会闪烁(当你在图片框中签名时,图片框会不断刷新)

是否有一种方法可以将其放入表单的加载事件中,使其只加载一次? 我知道它需要有PainEventArgs,但我不是很确定

    private void scSignature_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawRectangle(new Pen(Color.Black, 2f), 0, 0,
            e.ClipRectangle.Width - 1,
            e.ClipRectangle.Height - 1
            );
    }

谢谢

这当然不是一种优雅的方法,但是如果您可以确保图片框没有边框,您可以在picturebox容器控件上绘制一个实心矩形。 将其放置在图片框的正后方,并使其四周宽1px,使其看起来像图片框周围的1px边框

可能的示例(覆盖包含picturebox的控件的OnPaint方法):


这当然不是一种优雅的方法,但是如果您可以确保图片框没有边框,那么您可以在picturebox容器控件上绘制一个实心矩形。 将其放置在图片框的正后方,并使其四周宽1px,使其看起来像图片框周围的1px边框

可能的示例(覆盖包含picturebox的控件的OnPaint方法):


在CF中绘制时防止闪烁和垃圾产生的提示:

  • 覆盖OnPaintBackground并将其保留为空
  • 如果有多个操作,请不要直接绘制交给您的
    图形
    。而是创建一个
    位图
    缓冲区,绘制到该缓冲区中,然后将该位图的内容绘制到
    图形
  • 不要在上面的#2中为每一幅画创建缓冲区。创建一个缓冲区并重复使用
  • 不要重新绘制静态项(如签名控件中的框)。相反,将其绘制一次到缓冲的
    位图
    ,将该位图绘制到#2中的缓冲区,然后绘制动态项
  • 不要用每一种颜料来创作钢笔、画笔等。缓冲和重复使用
  • 在您的情况下,这些建议可能如下所示:

    class Foo : Form
    {
        private Bitmap m_background;
        private Bitmap m_backBuffer;
        private Brush m_blackBrush;
        private Pen m_blackPen;
    
        public Foo()
        {
            m_blackBrush = new SolidBrush(Color.Black);
            m_blackPen = new Pen(Color.Black, 2);
    
            // redo all of this on Resize as well
            m_backBuffer = new Bitmap(this.Width, this.Height);
            m_background = new Bitmap(this.Width, this.Height);
            using (var g = Graphics.FromImage(m_background))
            {
                // draw in a static background here
               g.DrawRectangle(m_blackBrush, ...);
                // etc.
            }
        }
    
        protected override void OnPaintBackground(PaintEventArgs e)
        {
        }
    
        protected override void  OnPaint(PaintEventArgs e)
        {
            using (var g = Graphics.FromImage(m_backBuffer))
            {
                // use appropriate back color
                // only necessary if the m_background doesn't fill the entire image
                g.Clear(Color.White);
    
                // draw in the static background
                g.DrawImage(m_background, 0, 0);
    
                // draw in dynamic items here
                g.DrawLine(m_blackPen, ...);
            }
    
            e.Graphics.DrawImage(m_backBuffer, 0, 0);         
        } 
    }
    

    在CF中绘制时防止闪烁和垃圾产生的提示:

  • 覆盖OnPaintBackground并将其保留为空
  • 如果有多个操作,请不要直接绘制交给您的
    图形
    。而是创建一个
    位图
    缓冲区,绘制到该缓冲区中,然后将该位图的内容绘制到
    图形
  • 不要在上面的#2中为每一幅画创建缓冲区。创建一个缓冲区并重复使用
  • 不要重新绘制静态项(如签名控件中的框)。相反,将其绘制一次到缓冲的
    位图
    ,将该位图绘制到#2中的缓冲区,然后绘制动态项
  • 不要用每一种颜料来创作钢笔、画笔等。缓冲和重复使用
  • 在您的情况下,这些建议可能如下所示:

    class Foo : Form
    {
        private Bitmap m_background;
        private Bitmap m_backBuffer;
        private Brush m_blackBrush;
        private Pen m_blackPen;
    
        public Foo()
        {
            m_blackBrush = new SolidBrush(Color.Black);
            m_blackPen = new Pen(Color.Black, 2);
    
            // redo all of this on Resize as well
            m_backBuffer = new Bitmap(this.Width, this.Height);
            m_background = new Bitmap(this.Width, this.Height);
            using (var g = Graphics.FromImage(m_background))
            {
                // draw in a static background here
               g.DrawRectangle(m_blackBrush, ...);
                // etc.
            }
        }
    
        protected override void OnPaintBackground(PaintEventArgs e)
        {
        }
    
        protected override void  OnPaint(PaintEventArgs e)
        {
            using (var g = Graphics.FromImage(m_backBuffer))
            {
                // use appropriate back color
                // only necessary if the m_background doesn't fill the entire image
                g.Clear(Color.White);
    
                // draw in the static background
                g.DrawImage(m_background, 0, 0);
    
                // draw in dynamic items here
                g.DrawLine(m_blackPen, ...);
            }
    
            e.Graphics.DrawImage(m_backBuffer, 0, 0);         
        } 
    }
    

    你在使用什么框架?Windows Mobile 6.5上的Compact Framework我就是这么想的。如果不是,我打算建议使用双缓冲,但Compact Framework没有Control.SetStyle方法。你在使用什么框架?Windows Mobile 6.5上的Compact Framework我就是这么想的。如果不是,我打算建议使用双缓冲't但紧凑框架没有Control.SetStyle方法。