开发者

WinForms performance mystery: derived PictureBox control slower than the original?

In my .NET 2.0 project, I made an empty derived class of System.Windows.Forms.PictureBox:

public class NewPictureBox : PictureBox
{
    //absolutely nothing 
}

Then I did the following:

  1. set both the derived control's and the base control's Image property to a rather large image (800x600), SizeMode is Normal (only the upper-left portion is displayed);
  2. hooked up several of the NewPictureBox's and PictureBox's events so a se开发者_运维知识库lection box can be drawn when dragging the mouse on the surface;
  3. set it up so the selection box's properties (Width/Height) will be updated on NumericUpDown controls in real time.

The problem is when dragging the mouse real fast on the derived PB, there is considerable "choppiness" compared to doing the same on the base PB. The Width/Height values are not updated in real time.

Does anybody know why is it like this? How do I achieve the same smoothness with the derived control? Thanks!

For anyone who wishes to check out the minimal sample project with the problem described:

http://www.mediafire.com/?i2nq2tmmjzx


Getting an image resized by PB to fit the control is very expensive. GDI+ has a very good filter but it doesn't come for free. Resize the image yourself before you assign it to the Image property so the PB doesn't have to resize it.

Using a bitmap created with Format32bppPArgb can make a big difference too, it is 10 times faster than any other format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜