移动PictureBox BackgroundImage丢弃透明度

我想移动PictureBox BackgroundImage以获得精灵功能,所以我继承了PictureBox并覆盖了OnPaintBackground:

    public class PictureBox1 : PictureBox
    {
        int bgX = 0,bgY = 0;

        public void SetImagePos(int X,int Y) {
            bgX = X;
            bgY = Y;
            Invalidate();
            Update();
        }

        protected override void OnPaintBackground(PaintEventArgs e) {
            //base.OnPaintBackground(e);
            e.Graphics.DrawImage(BackgroundImage,-bgX,-bgY,BackgroundImage.Width,BackgroundImage.Height);
        }       
    }

但是,这会丢弃透明度。带注释的//base.OnPaintBackground(e);带回了透明度,但背景还带有原始图像。我也尝试过e.Graphics.Clear(Color.Transparent),但背景颜色仍然是天鹅绒黑色。我想念什么?

我想要一个简单的解决方案,性能不是问题。

woaixu13142 回答:移动PictureBox BackgroundImage丢弃透明度

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3110078.html

大家都在问