Skip to content

Videos and gif into a windows form in c#

anon shenron

Asked Dec 3, 2014, 8:02 PM EST2 answers
Share
LinkedInX
how to make a video or a large format gif to be embeded and be used as a background for a windows form

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Ramu
    0
    C# WinForms application hosting the Windows Media Player control with a couple of specific properties set on the main form and the Media Player control.To start off the Windows Media Player, the Primary Interop Assembly needs to be installed and referenced. See this MSDN article for details on downloading and installing the Windows Media Player's PIA.
    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);
      }
    0
  • 1 short reply
    • 0
      thank you brother
      0