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
Directx painting in a picturebox/panel
Started by blacken, Dec 20 2012 02:26 PM
3 replies to this topic
Sponsor:
#3 Members - Reputation: 420
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);
DirectX for persians : http://mdirectx11.blogfa.com/
#4 Members - Reputation: 1597
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.
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.






