通过绘制控件背景图像来控制透明度

时间:2017-10-11 15:17:09

标签: c# bitmap transparency

我试图通过隐藏它来创建具有透明背景的标签,拍摄父级的快照,然后绘制父级的一部分作为该标签的背景。

这是我的代码

git lfs pull --recursive

我遇到的问题是,如果我把它放在例如。 picturebox它没有设置背景。我实际上已经尝试了这个

        protected override void OnMove(EventArgs e)
        {
            base.OnMove(e);
            Control highestParent = this;
            this.Hide();
            //Finds the topmost control, its panel that holds all other controls
            while (!(highestParent is Workground))
            {
                if(highestParent.Parent == null)
                {
                    this.Show();
                    return;
                }
                highestParent = highestParent.Parent;
            }

            Rectangle rec = new Rectangle(this.Location.X + 1, this.Location.Y + 1, Width, Height);
            Bitmap bmp = new Bitmap(Width, Height);
            highestParent.DrawToBitmap(bmp, rec);

            this.BackgroundImage = bmp;
            this.Show();
        }

它起作用,但只显示了父控件的左上角。

感谢您的帮助:)

更新:在Winforms中无法执行此操作。解决方案是切换到wpf。

0 个答案:

没有答案
相关问题