Substitute OnPaint c#

Started by
0 comments, last by Bearhugger 13 years, 6 months ago
Hi i have the next problem:

i have created in a .cs file a nameSpace called viewer3D and in its class viewer i have created all the necessary funtions to display meshes with SlimDX.

Now i am using this namespace from a form, and i want to use a panel control from this form to display the 3d view, so i need to change the OnPaint method of the panel for the OnPaint function that i have created in the class viewer

how can i make this?Here is the Onpaint functions of my viewer class:

 public void OnPaint(Control objeto)       {           myDevice.SetRenderState(RenderState.CullMode, true);           myDevice.SetRenderState(RenderState.FillMode, FillMode.Solid);           myDevice.SetRenderState(RenderState.Lighting, false);           myDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(Color.Gray), 1, 0);           myDevice.MultiplyTransform(TransformState.Projection,Matrix.PerspectiveFovLH(3.1415F/4,objeto.Width/objeto.Height,1.0F,500000F));           myDevice.MultiplyTransform(TransformState.View,Matrix.LookAtLH(new Vector3(0,170,70),new Vector3(0,170,0),new Vector3(0,1,0)));           myDevice.BeginScene();           myDevice.VertexFormat = VertexFormat.Position | VertexFormat.Texture1;           for (int i = 0; i < slimdxMeshList.Count; i++)           {               slimdxMeshList.DrawSubset(0);           }           myDevice.EndScene();           myDevice.Present();           objeto.Invalidate();       }
Advertisement
The IDirect3DDevice9::Present method has a parameter that let you to specify the window handle of the form you want it to draw on. Normally, you pass it NULL which means to tell the device to draw in the default window, but you can override it to draw somewhere else. That should let you draw with Direct3D anywhere.

I have no idea if the Panel object has its own hWnd property. If it does, just pass it that hWnd when you present and it should work. If the Panel object has no hWnd property of its own, it's because the panel is not "real" for Windows and its rendering is handled by WinForms, so pick the underlying WinForms component that has an hWnd property. In both cases, you have to adjust the viewport so it is properly scaled to the control.

This topic is closed to new replies.

Advertisement