在c#画图过程中,如果是直接在窗体上画图,那么增加以下代码很好的解决了问题构造函数中
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true); 在OnPaint函数中
BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
Graphics g = myBuffer.Graphics;
...(中间过程省略)
myBuffer.Render(e.Graphics);但是如果再窗体上增加一个Panel1控件,要在panel1上面画图,这时候以上代码就不管用了,画面会很闪控件好像又不能设置SetStyle属性,高手看看怎么解决
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true); 在OnPaint函数中
BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
Graphics g = myBuffer.Graphics;
...(中间过程省略)
myBuffer.Render(e.Graphics);但是如果再窗体上增加一个Panel1控件,要在panel1上面画图,这时候以上代码就不管用了,画面会很闪控件好像又不能设置SetStyle属性,高手看看怎么解决
版主的意思是不要把代码写在OnPaint里面
this.SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer, true);
我现在是这样的,一个panel里面,鼠标移上去之后,在panel里面显示一个跟随的十字线,当我鼠标停下来不懂时,横线就会没掉,竖线在的,目前就是这个问题未解决