I am using the System.Windows.Controls.MediaElement
in my ElementHost Control of the form called SplashScreen1.
In order to use the MediaElement, I have added the reference PresentationFramework.dll and imported the mediacontrol. Now I want to play the video called abc.wmv using my MediaElement object. The MediaElement object is instantiated as md and then set as the Child of the ElementHost object, elthst.
Following are the requirements:
1. I want to set the height and width of elthst to the height and width of md
2. The height and width of the SplashScreen1 should be as wide and long as the total width and height (+10)
Please see the code and please advise as to why the video is shrunk on the elthst and why the form is not centered at all.
Thanks
in my ElementHost Control of the form called SplashScreen1.
In order to use the MediaElement, I have added the reference PresentationFramework.dll and imported the mediacontrol. Now I want to play the video called abc.wmv using my MediaElement object. The MediaElement object is instantiated as md and then set as the Child of the ElementHost object, elthst.
Following are the requirements:
1. I want to set the height and width of elthst to the height and width of md
2. The height and width of the SplashScreen1 should be as wide and long as the total width and height (+10)
Please see the code and please advise as to why the video is shrunk on the elthst and why the form is not centered at all.
Thanks
VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SplashScreen1_Load([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] md [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Windows.Controls.MediaElement[/SIZE]
[SIZE=2] md.Source =
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Uri([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"C:\AppPath\abc.wmv"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] elthst [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ElementHost[/SIZE][SIZE=2]
[SIZE=2]
elthst.Location = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Location[/SIZE]
[SIZE=2] elthst.Child = md[/SIZE][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'elthst.Size = New System.Drawing.Size(md.Width, md.Height)
'md.Width and md.Height are NaN when I try to display them on MsgBox[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Controls.Add(elthst)[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].CenterToScreen()[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]'dynamically compute the size of the splash screen[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i, w, h [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2] w = 0
h = 0
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0 [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Controls.Count - 1[/SIZE]
[SIZE=2] w +=[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Controls(i).Width[/SIZE]
[SIZE=2] h +=
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Controls(i).Height[/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Size = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Drawing.Size(w + 10, h + 10)[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE]