Move form should move video as well

Hi,
My application is a simple mediaplayer, capable of playing two video files (shown in two UserControls on a Mdi child form in aTableLayoutPanel, Dock.Fill) at the same time. When I move the Mdi parent or child form (with its two UserControls) the video output does not move as wanted (part of the video is cut off).
What I've done:
If the Move event is fired (mdi child form), then the following method in the UserControl is called:



void
ChildForm_Move(object sender, System.EventArgs e)
{

Rectangle rect;
// videoWindow1 is a UserControl
rect = videoWindow1.RectangleToScreen(videoWindow1.ClientRectangle);

}


publicvoid MoveVideoWindow(int left,int top,int width,int height)
{
int hr = 0;
// Track movement and resize - UserControl method
if (this.videoWindow != null)
{
// videoWindow is of type IVideoWindow
hr = this.videoWindow.SetWindowPosition(
left,
top,
width,
height
);
DsError.ThrowExceptionForHR(hr);
}
}


How can I make the video move correctly? I am using DirectShowNet.
Thank you!

[1720 byte] By [LewsTherin] at [2008-1-4]
# 1

In the Form_Move handler, after setting rect, you are supposed to call MoveVideoWindow !! See the correct code in Players/PlayWnd sample :

Code Snippet

private void MainForm_Move(object sender, System.EventArgs e)
{
if (!this.isAudioOnly)
MoveVideoWindow();
}

private void MoveVideoWindow()
{
int hr = 0;

// Track the movement of the container window and resize as needed
if (this.videoWindow != null)
{
hr = this.videoWindow.SetWindowPosition(
this.ClientRectangle.Left,
this.ClientRectangle.Top,
this.ClientRectangle.Width,
this.ClientRectangle.Height
);
DsError.ThrowExceptionForHR(hr);
}
}

MichelRoujansky at 2007-10-11 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 2

Hi,

Of course I am calling MoveVideoWindow, just forgot to paste it here. The picture moves, but not as desired. It moves faster, than the form. The problem is obtaing the correct values for rect.Left and rect.Top. When I resize the form, the video is shown correctly in the center of the UserControl, because rect.Left/rect.Top is not needed, is 0.

It worked in the past, but I did not use a UserControl - instead I used a panel and put all code in the mdi child form. Someone suggested I'd need to translate screen coordinates from all containers, but I'm not sure how to do this.

Thanks

LewsTherin at 2007-10-11 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 3

I still have not found any solution. Is there no one else, who put all code in a UserControl? How do you guys do it?

Thanky you

LewsTherin at 2007-10-11 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 4

Have you tried to compute and use as coordinates for the move the screen position of your user control? (you have to take into account the screen position of your window, plus the position of the control within the window)

MichelRoujansky at 2007-10-11 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 5

Yes, I've tried this, but I'm not sure how exactly it's done. Do you know of any good example?

Thanks

LewsTherin at 2007-10-11 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...

Software Development for Windows Vista

Site Classified