Answered ridiculous media player glitch

Snyper

New member
Joined
Apr 10, 2009
Messages
2
Programming Experience
10+
I'm working on an app which has a secondary form with a wmp object on it to act as a preview.
My problem is that when the app is run and the form is viewed everything works fine, but when you close the form (or hide) and come back to it the wmp object has resized itself to 300x300.

I've tried everything including monitoring sizechange and resetting it, setting size on form open, etc. It appears that a number of the objects settings are getting reset but i seem to be able to set all of them back except the size property.

I don't understand why this is happening, I'm not destroying the control at any point, just hiding the form it is on.

This is reproducible by doing the following ...
1. on the main form put a button which opens a 2nd form with .show or .showdialog
2. create a second form, put an exit button on it with a me.close or similar event attached.
3. drag a wmp object to it and size it to something like 200x200 or whatever.
4. on the loadevent for the form assign a picture to the wmp control. eg wmp.url="C:\abc.jpg"

now when you run it and click the button to show the form it will be ok, but when you then 'exit' the 2nd form and open it again the wmp control will have resized to 300x300

can somebody please let me know how to stop this happening.
 
Last edited:
I have reproduced the bug (autosizes to content size) when using ShowDialog with a default form that is not disposed and then redisplayed without changing url. If this applies to you then remember to Dispose the form after ShowDialog.

I have not found this happening in any other tested cases around what you mention.
 
I can't believe it was that simple. I've never thought of disposing a form before, and have never seen anyone else do it in code samples. It now works perfectly though.

Thanks tons!
 
The help for Form.ShowDialog Method explains this, the code sample includes the Dispose call. Also if you read the help for Form.Close Method you'll see this explained. There is also a good reason for this design and behaviour, modal dialogs is commonly used to get data/choices from user, after the dialog is returned you retrieve the dialog result and possibly the data. If the form was already disposed and cleaned up that data would be lost before you got a chance to read it. Another way of proper disposal of forms with ShowDialog is the Using code block. There may be reasons to keep a dialog form active between displays, too.
 
Back
Top