SharpDX WindowRenderTarget Clear становится черным - PullRequest
0 голосов
/ 29 ноября 2018

Я пытаюсь сделать прозрачный фон в форме Windows, чтобы нарисовать на нем некоторые тексты, чтобы он работал как HUD перед другими запущенными программами.

Но Device.Clear (Color.Transparent)) не работает, фон становится черным, вот мой текущий код:

public HUD()
        {

            InitializeComponent();

            var renderProp = new HwndRenderTargetProperties
            {
                Hwnd = this.Handle,
                PixelSize = new Size2(Client.GameScreen.width, Client.GameScreen.height),
                PresentOptions = PresentOptions.None
            };

            Device = new WindowRenderTarget(
                new SharpDX.Direct2D1.Factory(),
                new RenderTargetProperties(
                    new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied)
                ),
                renderProp);

        }

private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
            this.Text = "";
            this.AutoSize = false;

            // Code to Set the Size Here....

            this.UseWaitCursor = false;
            this.Cursor = null;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.TopMost = true;

            this.BackColor = Color.LimeGreen;
            this.TransparencyKey = Color.LimeGreen;

            this.ForeColor = Color.White;
            this.DoubleBuffered = true;
            this.PerformLayout();
            this.ResumeLayout(false);

        }

Код выше - это класс HUD, расширяющий класс Form, и в моем главном окне цикл запускаетсяновый поток:

var hud = new HUD();
void RunHud()
        {
            while (true)
            {

                // Clear the target. 
                hud.Device.BeginDraw();

                hud.Device.Clear(Color.Transparent.ToRaw()); //Extension method to convert to RawColor4

                hud.Device.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased;
                hud.Device.AntialiasMode = AntialiasMode.Aliased;

                // Draw a block of text that will be clipped against the specified layout rectangle.
                hud.Device.DrawText("This text is long enough to overflow the designed region but w. ", textFormat, new SharpDX.Mathematics.Interop.RawRectangleF(500, 500, 700, 700), textBruch, DrawTextOptions.Clip);

                hud.Device.EndDraw();

                Thread.Sleep(10);
            }
        }

Это просто "Hello World" для тестирования SharpDX, я пробовал много разных цветов в Device.Clear () и в моей форме BackColor / TransparencyColor.

Я использую Windows 7, VS2017 и SharpDX 4.2, не уверен, что я что-то упустил.

...