Directx painting in a picturebox/panel

Started by
2 comments, last by unbird 11 years, 4 months ago
Hi Guys,

Just wondering if someone would be able to help me out.

I am trying to paint my directx in a picturebox or panel. I have managed to get it working by painting to the form with the protected override void onPaint function and using onPaintBackground to avoid flicker.

However, i am trying to map this over to picturebox or panel however i can't find an onPaintBackground function to prevent flicker in the picturebox/panel.

If there is any information someone would be able to provide to prevent this flicker, that would be great. The main reason i am trying to do this is so that i can put other controls in the form and painting the whole form doesn't allow use of the controls at runtime.

Thanks
Advertisement
I usually handle all drawing in the Application::OnIdle event. That way it does not matter what UI Component you are using then it becomes pretty straightforward because you can create an renderable ui with the component Handle.

hi,

i am using the following codes in my programs:

in Program class :


    static class Program
    {
        static int Main()
        {
            var frm = new MainWindow();
            frm.Show();
            while (frm.Created)
            {
                frm.UpDate(0);
                frm.Render();
                Application.DoEvents();
            }
            return 0;
        }
    }

in MainWindow Class:


public partial class MainWindow : Form
{
    //RenderPanel is a Panel Control for Rendering the contents
    public IntPtr RenderPanelHandle { get { return RenderPanel.Handle; } }
    public MainWindow()
    {
        InitializeComponent();
    }
    public void UpDate(float dt)
    {
          //SomeCodes
    }
    public void Render()
    {
          //SomeCodes
    }
    //Others
}

the following code create a Device that render the contents in RenderPanel:


SlimDX.Direct3D9.Device d = new SlimDX.Direct3D9.Device(direct3D, 0, DeviceType.Hardware, RenderPanelHandle ,
                                                                    CreateFlags.MixedVertexProcessing, pp);

???? ?? ??? ????

Persian Gulf

To prevent OnPaintBackground (or anything else that causes that flicker) you need to dig deeper into the Windows API or the .NET Framework - or both.

Inheriting a control (preferably UserControl) and overriding OnPaintBackground with not calling base.OnPaintBackground() is one possibility.

There's also the control style flag ControlStyles.Opaque: Enable it through Control.SetStyle. Look into the other styles (AllPaintingInWmPaint, UserPaint). Again, this method is protected, so you need to inherit here.

Sometime going bare Win API by e.g. overriding WndProc or use p/invoke is even needed (not in this case though).

PS: Additional advice: To do it cleanly, you should use a custom swapchain - for every control.

This topic is closed to new replies.

Advertisement