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:
- set both the derived control's and the base control's
Image
property to a rather large image (800x600),SizeMode
isNormal
(only the upper-left portion is displayed); - hooked up several of the
NewPictureBox
's andPictureBox
's events so a se开发者_运维知识库lection box can be drawn when dragging the mouse on the surface; - set it up so the selection box's properties (
Width
/Height
) will be updated onNumericUpDown
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.
精彩评论