I am rendering in a picturebox that is inside a panel and it is inside of a Form, because my application is windowed and is like a level editor, I have buttons and other controls in my Form.
I want to change the size of the picturebox and dynamically change the the rendering resolution. The picture box hasnÂ´t a 4:3 relation, is an arbitrary resolution and relation.
I donÂ´t know why, I tried to change the resolution in many ways but nothing works.
I probably can help you. I am working on a editor with Mogre and so far it works like a charm. I have a my "ViewControl" which is basically just a UserControl that renders with Mogre. It has a RenderWindow, a Viewport and a Camera.
In the OnResize method, I notify the RenderSystem that the window is resized and then I repaint it.
protected override void OnResize(EventArgs e)
if (m_window != null)
// Update your cameras here...
m_camera.AspectRatio = (float)m_viewport.ActualWidth /
// Render a frame.
If you need more help, let me know, I can post more code or give more explanation.
PS : Dont expect the resizes to be efficients. Direct3D is very sensitive to resizes with the device lost and stuff. So expect some flickering and/or slowdowns during resize. Use with care.
Well I tried very much.
What I am doing now is destroy the RenderWindow, create it again and create the viewport again, and it works now I have the resolution of the Control.
If I only change the aspect ratio the RenderWindow doesntÂ´t change the resolution.
I donÂ´t know if you get the same?, when you resize your control, the viewport.ActualHeight and Width also changes? In my application if I resize the control the image resizes also but the viewport maintains its actualheight and actualwidth.
When my control resizes I call this:
public class MogreAdmon
root = new Root();
public void CreateWindow(System.Windows.Forms.Control control, Mogre.Camera camera)
if (renderWindow != null)
NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = control.Handle.ToString();
renderWindow = root.CreateRenderWindow("Window name", (uint)control.Width, (uint)control.Height, false, misc); //Actually it seems the Width and Height in this function doesnÂ´t matter if it has externalWindowHandle in misc
//Recreate the viewport
if(camera != null)
viewport = renderWindow.AddViewport(camara);
Class Control : Some Control or PictureBox
actualCamera.AspectRatio = (float)viewport.ActualWidth / (float)viewport.ActualHeight;
With this now I get a clear image not a redimensioned image.
Try this in your code, change the control size to (160,120) immediately before you create the renderWindow, now use your control in a bigger size like 640,480. If I do this without recreate the renderWindow the actual resolution is 160x120 but it is scaled to 640x480 then I change the control size.
You are right, by default, the control will resize but the rendering size will remain the same. Which mean you image will merely be streched to fit the control. This is no good.
But, I dont think you looked carefully at my code. At some point I call the method WindowMovedOrResized() on the window. This is the trick!
This method will trigger the resize in Direct3D. Try it! If it doesnt work, Let me know, I can simply post all my code in here!
Hey bleubleu hehehe, I thinked WindowMovedOrResized was a method implemented by you hahahaha , ouch, I solved the problem in another way but hahaha WindowMovedOrResized is less code, well well I will try,
I tried and it work well, with WindowMovedOrResized, thanks .