有没有办法在没有pictureBox和没有任何控制的情况下在屏幕上绘制图形?

时间:2016-12-17 17:46:40

标签: c# .net winforms directx

在这个方法中,我需要给它一个pictureBox:

private Boolean InitializeDirectX()
        {

            DispMode = Manager.Adapters[Manager.Adapters.Default.Adapter].CurrentDisplayMode;
            D3Dpp = new PresentParameters();
            D3Dpp.BackBufferFormat = DispMode.Format;
            D3Dpp.PresentFlag = PresentFlag.LockableBackBuffer;

            D3Dpp.SwapEffect = SwapEffect.Discard;
            D3Dpp.PresentationInterval = PresentInterval.One; //wait for vertical sync. Synchronizes the painting with
                                                              //monitor refresh rate for smoooth animation
            D3Dpp.Windowed = true; //the application has borders

            try
            {
                D3Ddev = new Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, pb1.Handle,
                                                                           CreateFlags.SoftwareVertexProcessing, D3Dpp);
                D3Ddev.RenderState.Lighting = false;
                D3Ddev.RenderState.CullMode = Cull.CounterClockwise;


                backTexture = TextureLoader.FromStream(D3Ddev, mymem);
                scannedCloudsTexture = new Texture(D3Ddev, 512, 512, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);

                //sprite is used to draw the texture
                D3Dsprite = new Sprite(D3Ddev);

                return true;
            }
            catch
            {
                return false;
            }
        }

该行是:

D3Ddev = new Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, pb1.Handle,                                                                          CreateFlags.SoftwareVertexProcessing, D3Dpp);

pb1应该是pictureBox,我应该把pictureBox Handle放在那里。 但是相反,一个pictureBox可能有一种方法可以自己使用它?

我看到了一些东西:

System.Windows.Forms.Screen.FromHandle

但不确定这是否是我需要的。它还需要获得intptr。

0 个答案:

没有答案