//控件构造函数
public GanttChart()
{
//先绘制位图作为背景
objBmp = new Bitmap(1280, 1024, System.Drawing.Imaging.PixelFormat.Format24bppRgb);//定义位图
objGraphics = Graphics.FromImage(objBmp);//绘制图片,作为背景 //无闪烁绘制的设定
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
}
//重绘方法
private void PaintChart(Graphics gfx)
{
DrawMarkEllipse(gfx, rectangleLTPoint, rectanglesideLength, rectanglesideHigh);//绘制标记椭圆
objBmp = new Bitmap(this.Width - barStartRight, lastLineStop, System.Drawing.Imaging.PixelFormat.Format24bppRgb);//前两个参数为宽和高
objGraphics = Graphics.FromImage(objBmp);
}//画椭圆方法定义
private void DrawMarkEllipse(Graphics gfx, Point rectangleleftup, int length, int height)
{
Graphics graphics = this.CreateGraphics();
Pen = new Pen(Color.Black, 3);
Rectangle rectangleside = new Rectangle(rectangleleftup.X, rectangleleftup.Y, length, height);
graphics.DrawEllipse(, rectangleside);
}//双击事件中,调用重绘方法
protected override void OnMouseDoubleClick(MouseEventArgs e)
{
PaintChart(gfx); //我想在控件上双击一下,就在控件相应位置画一个椭圆
}问题是可以画出椭圆,但是我鼠标在控件界面上移动时,椭圆是在不断闪烁(就是一会有,一会无,交替出现,频率很快)??这是怎么回事,我的代码怎么改进可以让他不闪烁???
解决方案 »
- IIS
- 动态生成Timer控件,分别用来向串口发送接收数据,现在只有最后一个打开的串口能收发数据!
- 如何改变网格控件模板列中控件的值
- 如何在FORM传到WINFORM
- winform当中,DataGrid某一列如何绑定图片呢?
- 有个叫杭州嘉禾软件公司的,有没有人听说过
- 急!!用xml作为数据源,通过datagrid显示,如何动态添加新列并将新列的数据写回xml文件里???大家帮帮忙,分不够可以再加!!!!!!
- 【提问】老革命遇到新问题之四:关于SmartClient的开发。
- 哪位高手可以帮忙解释下overload和override的作用用法吗?
- System.Text.Encoding.get_Unicode().GetString(m_pcName,0,m_pcName.length).toString();编译报错
- C#开发软件这个按钮如何变成这样?写什么样式..
- 关于获取文件路径的问题,求助!
我把代码该了,是在鼠标双击的时候重绘,还是闪烁呢?是不是我位图作为背景防止闪烁有问题??//控件构造函数
public GanttChart()
{
//先绘制位图作为背景
objBmp = new Bitmap(1280, 1024, System.Drawing.Imaging.PixelFormat.Format24bppRgb);//这个位图自己都没搞懂干嘛的???
objGraphics = Graphics.FromImage(objBmp);//绘制图片,作为背景???? //无闪烁绘制的设定
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
}protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)//重写OnPaint方法
{
base.OnPaint(pe); PaintChart(pe.Graphics);
}//重绘时候调用
public void PaintChart()
{
this.Invalidate();//该方法会使得整个控件工作区无效,进行重绘
}
//重绘方法
private void PaintChart(Graphics gfx)
{
DrawMarkEllipse(gfx, rectangleLTPoint, rectanglesideLength, rectanglesideHigh);//绘制标记椭圆
objBmp = new Bitmap(this.Width - barStartRight, lastLineStop, System.Drawing.Imaging.PixelFormat.Format24bppRgb);//这个位图自己都没搞懂干嘛的???
objGraphics = Graphics.FromImage(objBmp);//这个位图自己都没搞懂干嘛的???
}//画椭圆方法定义
private void DrawMarkEllipse(Graphics gfx, Point rectangleleftup, int length, int height)
{
Graphics graphics = this.CreateGraphics();
Pen = new Pen(Color.Black, 3);
Rectangle rectangleside = new Rectangle(rectangleleftup.X, rectangleleftup.Y, length, height);
graphics.DrawEllipse(, rectangleside);
}//双击事件中,调用重绘方法
protected override void OnMouseDoubleClick(MouseEventArgs e)
{
PaintChart(); //我想在控件上双击一下,就在控件相应位置画一个椭圆
}问题是可以画出椭圆,但是我鼠标在控件界面上移动时,椭圆是在不断闪烁(就是一会有,一会无,交替出现,频率很快)??这是怎么回事,我的代码怎么改进可以让他不闪烁???
我知道哪里错了!哈哈 DrawMarkEllipse方法中的应该用gfx绘图,而不是去自己重新新建private void DrawMarkEllipse(Graphics gfx, Point rectangleleftup, int length, int height)
{
//Graphics graphics = this.CreateGraphics();
Pen = new Pen(Color.Black, 3);
Rectangle rectangleside = new Rectangle(rectangleleftup.X, rectangleleftup.Y, length, height);
gfx.DrawEllipse(, rectangleside);
}谢谢高手!尤其是2楼了,你帮了我很多次了!