最近開發一個基于windows mobile 6.5的小程序,需在要一個自定義控件上繪制線條,采用了雙緩沖的方法 ,但是程序運行時,發現滾動屏幕時,這根線條還是在閃爍,請看下面的代碼 protected override void OnPanit(PaintEventArgs e){ Bitmap bmp = new Bitmap(this.width,this.height); Graphic g = Graphics.FromImage(bmp); g.Clear(Color.White); g.DrawLine(Pens.Black, 2, 2, 100, 100); e.Graphic.DrawImage(bmp); bmp.Dispose();}請大家指點一下這段代碼有什么問題
1 回答

米琪卡哇伊
TA貢獻1998條經驗 獲得超6個贊
把 e.Graphic.DrawImage(bmp); 換成
this.CreateGraphics().DrawImage(bmp);
在你的控件初始化的時候添加下面的代碼:
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
this.UpdateStyles();
- 1 回答
- 0 關注
- 323 瀏覽
添加回答
舉報
0/150
提交
取消