Jump to content
  • Advertisement
Sign in to follow this  
happyrobbie

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

This topic is 4708 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!