Sign in to follow this  

Directx painting in a picturebox/panel

This topic is 1852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites
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. Edited by unbird

Share this post


Link to post
Share on other sites

This topic is 1852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this