jingwood / d2dlib

A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
MIT License
234 stars 40 forks source link

Draw Transparent shape over transparent WinForm #66

Open mostafa901 opened 3 years ago

mostafa901 commented 3 years ago

Can say how much I liked your lib. Thanks indeed!

I come up to hide a winform window and tried to draw semitransparent shapes over, but it didn't work so well. see this quick code.

public class TransientWindow : D2DForm
    {
        public TransientWindow()
        {
            BackColor = System.Drawing.Color.FromArgb(255, 255, 255, 255);
            TransparencyKey = BackColor;
            FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            AllowTransparency = true;
        }

        protected override void OnRender(D2DGraphics g)
        {
            g.Clear(D2DColor.FromGDIColor(BackColor));

            g.FillRectangle(50, 50, 500, 500, new D2DColor(.1f, D2DColor.CornflowerBlue));
            g.DrawText("This is a test", new D2DColor(.2f, D2DColor.Red), "Arial", 20, 50, 50);
        }
    }

image

not sure if it is to draw a bitmap of the shape area, that to be used as a background to the shape to simulate transperency? seems too expensive.

Thoughts?

jingwood commented 3 years ago

Hi! Glad to know that it helps you!

I will have a check on how to implement a semi-transparent rendering.