videos and gif into a windows form in c#
how to make a video or a large format gif to be embeded and be used as a background for a windows form
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
anon shenronPosted Dec 4, 2014, 11:03 PM
RamuPosted Dec 4, 2014, 4:12 AM
After inserting the Windows Media Player control onto the form, the following three properties need to be set on the control:
- uiMode - None since we don't want the Media Player's controls visible, we only want to see the video stream.
- windowlessVideo - true since we want the Media Player to use the control host's (our main form's) window and not create its own child window in which to render the video. The reason for this is that the layered windows transparency support in the OS that we're making use of only works for top-level windows and not for child windows. See the MSDN article for more details.
- URL - source of the video. This can refer to an existing video, e.g. file:///c:/somevideo.wmv or to a video being streamed, e.g. http://somehost/.
Then the following properties need to be set on the form:- FormBorderStyle - None
- Topmost - true
- WindowState - Maximized
- Opacity - 0.55 or whatever amount of transparency you'd like to use.
In the Form's Load event we need to add the WS_EX_TRANSPARENT extended window style to our form's window in order for input events from the mouse and keyboard to be passed through to the underlying windows.Use This Code:
[DllImport("user32.dll", SetLastError=true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError=true)]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private const int GWL_EXSTYLE = -20;
private const int WS_EX_TRANSPARENT = 0x20;
private void VideoPlayer_Load(object sender, System.EventArgs e)
{
// Add WS_EX_TRANSPARENT style so that mouse, keyboard etc. events pass
// thru us.
int exstyle = GetWindowLong(this.Handle, GWL_EXSTYLE);
exstyle |= WS_EX_TRANSPARENT;
SetWindowLong(this.Handle, GWL_EXSTYLE, exstyle);
}