[MDX / c#] problem when resizing the control...

Started by
2 comments, last by happyrobbie 18 years, 3 months ago
This should be a naive problem but it costs me a whole hour without any solution... First i create a simple form that shows a sphere:

public partial class TestForm1 : Form
{
	public TestForm1()
        {
            InitializeComponent();
            Init();
        }

	protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Render();
        }

	private void Init()
	{
		//codes for initializing d3d graphics goes here...
	}

	private void Render()
	{
		//render codes goes here...
	}

	private Device device;
}





Everything works well as supposed, except two things. First, when i enlarge the form, the d3d scene will automatically resize itself to fit, but the scene refuse to shrink itself when i shrink the form so the sphere is simply "clipped". Second, if i resize the form to zero size, i'll get an exception. See, below: Error in the application. -2005530585 (D3DERR_DRIVERINTERNALERROR) at Microsoft.DirectX.Direct3D.Device.Reset(PresentParameters[] presentationParameters) at Microsoft.DirectX.Direct3D.Device.OnParentResized(Object sender, EventArgs e) at System.Windows.Forms.Control.OnResize(EventArgs e) at System.Windows.Forms.UserControl.OnResize(EventArgs e) at System.Windows.Forms.Control.OnSizeChanged(EventArgs e) at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight) at System.Windows.Forms.Control.UpdateBounds() at System.Windows.Forms.Control.WmWindowPosChanged(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.UserControl.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) Actually what i need is not an entire form showing a sphere but rather a user control that can be reused on many forms. So a step further, i make a d3d user control that shows a sphere:

public partial class TestControl : UserControl
{
	public TestControl()
        {
            InitializeComponent();
            Init();
        }


	protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Render();
        }


	private void Init()
	{
		//codes for initializing d3d graphics goes here...
	}


	private void Render()
	{
		//set up matrices, materials, lights...

		//draw the sphere
	}


	private Device device;
}





and then add this control to a form, setting the control's Dock property to "Fill" 'cause i wanna it to resize itself to fit the area of its parent form.

public partial class TestForm2 : Form
{
        public TestForm2()
        {
            InitializeComponent();
        }


        public static void Main(string[] args)
        {
            TestForm2 form2 = new TestForm2();
            TestControl control = new TestControl();
            control.Parent = form2;
            control.Dock = DockStyle.Fill;  
            Application.Run(form2);
        }
}





Everything seems nice at first, though the two old problems still exist. However, a new problem emerges, which is probably a vital one. if i simply minimize the form, the same exception will also occur. can anyone tell me why it works like this? [Edited by - happyrobbie on December 29, 2005 12:49:49 AM]
Advertisement
and, the mdx sdk tutorials themselves also have the same thing. try resizing the form to zero size and wait for the exception... and if u make very little modifications, changing the forms in those samples into controls and addd the controls to other forms (setting the DockMode to "Fill") and try minimizing the form...
i've tried a few means, including handle the device's Reset or Resize event manually, but none seems to be of help.

[Edited by - happyrobbie on December 29, 2005 12:10:07 AM]
u can give the window minimum size bigger than (0,0) in order not to face this problem
Great, it works... ^_^
This should have been the first solution coming to my mind...
but i still wonder why doesn't the api silently deal with the zero-size like all other windows controls instead of throwing an exception. Minimizing is so common an action that all controls should take their own charge instead of relying on setting some particular properties such as the minimum size...

This topic is closed to new replies.

Advertisement