Windows Forms and DirectX

Started by
8 comments, last by Modena_au 18 years, 8 months ago
Hello all. I'm hoping to whip up some tools for my latest project in C# and DirectX. What I'd like to be able to do is to create a Direct3D instance inside a window and have standard windows controls along the left hand side and along the bottom. Basically all I really need to know is if I can create a Direct3D instance inside some control, such as a panel. Thanks for your time.
Advertisement
Indeed, you can. I'm not entirely sure which controls will work and which won't, though, but I do know for sure that the PictureBox does work, as that's what I've always used (pre-.NET as well as in Windows Forms) when a basic window didn't do the job.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Perfect, thanks. I'll have to try that after work. So just to be clear, when creating your Direct3D instance, you simply attach the code to the picture box, as apposed to the window intself? (I'm normally an openGL/SDL guy, but I wanted to give the otherside a try, so what better way than .net/DirectX/C# :)).
Hi there Modena_au,
How are you doing?
Sure, when creating the device you just pass it the handle of the control you are attaching it to.

[Example]
I would say the best control to use would be the System.Windows.Forms.Panel.
Here is an example.
[source lang = c#]device = new Device(0, DeviceType.Hardware, control.Handle, CreateFlags.HardwareVertexProcessing, pparams);


Hope this helps :)
Whenver you are specifying the render target (when you vreate the device), just set it to the control (picturebox or whatever)... I think that should do it.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Thanks guys. You've made it seem so easy, I'm almost embarrased I had to ask :).
Quote:Original post by Sr_Guapo
Whenver you are specifying the render target (when you vreate the device), just set it to the control (picturebox or whatever)... I think that should do it.


sorry friend how can create a device without specified the render target?

Quote:Original post by Say
Quote:Original post by Sr_Guapo
Whenver you are specifying the render target (when you vreate the device), just set it to the control (picturebox or whatever)... I think that should do it.


sorry friend how can create a device without specified the render target?


Actually, you still specify a render target, you just use whatever control instead. When you create a device in managed DX, you must pass a few things:

D3DDevice = New Device(AdapterNum, device type, render target, flags, Presentation parameters);Example:dev = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, picturebox1, flags, pp)


Just change the "render target" parameter to the control you want. I am sure it will work with picture boxes and oanels, but I have no idea with other controls.

Quote:Original post by Modena_au
Thanks guys. You've made it seem so easy, I'm almost embarrased I had to ask :).


Don't feel bad. DX can be fairly easy to set up and such, but once you start getting into it, there are thousands of functions and things to keep track of. It is impossible to remember every little function call and how to implement every littlething. That is why I love the forums so much. You can either search foir a solution (through google until they fix it [wink]) or ask yourself.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Well... I'm back with more questions already :S
I have this code:
PresentParameters presentParams = new PresentParameters();presentParams.Windowed = true;presentParams.SwapEffect = SwapEffect.Discard;device = new Device(0, DeviceType.Software, pnlRender, CreateFlags.SoftwareVertexProcessing, presentParams);

And it's throwing a DirectXException when calling the Device constructor. I've trying Software, hardware and NullRefernce as Device types and both software and hardware vertex processing for the create flags. So I'm wondering, is there anything special I have to do to prepare the pnl (other than calling the constructor and placing it) or is the problem in my presentParams? Or the equally plossible third option, I'm totally missing the problem here :D.
Sorry, I'm a little slow tonight, I forgot to call panels constructor.

This topic is closed to new replies.

Advertisement