I would like to create a overridden picturebox control that accepts a colormatrix as a property, and when the picturebox is drawn it uses that colormatrix. This is to cut down on drawimage GDI calls that are slowing down my app. I would love to turn 2 into 1, and cut down form 3 image objects to 1. But when decompiling the Windows.Forms.PictureBox I find that its onPaint method is an override of the Windows.Forms.Control's onPaint method and its don't a hefty amount of sealed work that I can't seem to compile. here is the original onPaint
protected override void OnPaint(PaintEventArgs pe)
{
if (this.pictureBoxState[0x20])
{
try
{
if (this.WaitOnLoad)
{
this.Load();
}
else
{
this.LoadAsync();
}
}
catch (Exception exception)
{
if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
{
throw;
}
this.image = this.ErrorImage;
}
}
if (this.image != null)
{
this.Animate();
ImageAnimator.UpdateFrames();
Rectangle rect = (this.imageInstallationType == ImageInstallationType.ErrorOrInitial) ? this.ImageRectangleFromSizeMode(PictureBoxSizeMode.CenterImage) : this.ImageRectangle;
pe.Graphics.DrawImage(this.image, rect);
}
base.OnPaint(pe);
}
and here is what I want it to look like
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
{
if (base.pictureBoxState[0x20])
{
try
{
if (this.WaitOnLoad)
{
this.Load();
}
else
{
this.LoadAsync();
}
}
catch (Exception exception)
{
if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
{
throw;
}
base.image = this.ErrorImage;
}
}
if (base.image != null)
{
base.Animate();
ImageAnimator.UpdateFrames();
Rectangle rect = (base.imageInstallationType == base.ImageInstallationType.ErrorOrInitial) ? base.ImageRectangleFromSizeMode(PictureBoxSizeMode.CenterImage) : base.ImageRectangle;
if (PaintCM == new ColorMatrix())
{
pe.Graphics.DrawImage(base.image, rect);
}
else
{
ImageAttributes ia = new ImageAttributes();
ia.SetColorMatrix(PaintCM);
pe.Graphics.DrawImage(base.image, rect, 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, ia);
}
}
base.OnPaint(pe);
}
Problem is, It won't compile because those objects it want to use are sealed internal classes to the Windows.Forms library.
So is there anything I can do? I don't want to start from scratch on a control that does this because I have already done EXTENSIVE work from a picturebox control base and I don't want to ruin the hours I spent on all that code, I'm afraid I won't be able to pull up the same centering zoom effect.
But any input would be appreciated. I will do it from scratch if I have to. I just really would like not to, if you know what I mean.