Jump to content

  • Log In with Google      Sign In   
  • Create Account

Directx painting in a picturebox/panel


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 blacken   Members   -  Reputation: 126

Like
0Likes
Like

Posted 20 December 2012 - 02:26 PM

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

Sponsor:

#2 BornToCode   Members   -  Reputation: 925

Like
0Likes
Like

Posted 20 December 2012 - 06:33 PM

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.

#3 hossainiir   Members   -  Reputation: 1008

Like
1Likes
Like

Posted 21 December 2012 - 03:37 AM

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


#4 unbird   Crossbones+   -  Reputation: 4974

Like
0Likes
Like

Posted 21 December 2012 - 07:40 AM

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, 21 December 2012 - 08:29 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS