C#Graphics.Clear(Color.Transparent)无法正常工作?

Wol*_*and 7 c# graphics transparency

我反复在控制区域绘制一些图形,每次我想以透明背景开始新鲜.所以我使用:

Graphics graph = control.CreateGraphics();
graph.Clear(Color.Transparent);
Run Code Online (Sandbox Code Playgroud)

但是,图形区域似乎变成黑色而不是透明.有任何想法吗?

Wol*_*and 5

我找到了一种替代方法来实现我所需要的。我创建了一个具有控件尺寸的新透明位图,在其上绘制我的内容,然后将其用作控件的背景图像:

    Bitmap bitmap = new Bitmap(control.Width, control.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
    bitmap.MakeTransparent();
    Graphics graph = Graphics.FromImage(bitmap);

    //  draw stuff here ...

    control.BackgroundImage = bitmap;
    graph.Dispose();
Run Code Online (Sandbox Code Playgroud)

这完美地工作。