0

I have a wpf application where several pages are displayed inside a window (using uniformgrid with dynamically added frames). The pages get rearranged inside the window when special events are called. The problem is: sometimes I have to call a System.Windows.Forms form inside a page. I want this form to be displayed on top of the page (overlaying the page). I already calculated the position:

StatusForm frm = new StatusForm (m_object, parameters);
frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
Point topleftPageCoord = this.PointToScreen(new Point(0, 0));// get topleft coordinates of the page
int x = (int)topleftPageCoord.X + ((int)this.ActualWidth - frm.Size.Width) / 2;
int y = (int)topleftPageCoord.Y + ((int)this.ActualHeight - frm.Size.Height) / 2;
frm.Location = new System.Drawing.Point(x, y);
frm.ShowDialog();
if (frm.Result != "") do something;

but when my whole window gets rearranged the form is (of course) still at this old position. Is there a way to call the form with the page as owner? So that the form is somehow connected to the page and automatically moved when the page is moved?

purbsel
  • 307
  • 8
  • 21
  • When you say "form" do you mean a Window or a Control? – Meirion Hughes Aug 07 '14 at 06:59
  • I mean a standard System.Windows.Forms.Form (FixedToolWindow) – purbsel Aug 07 '14 at 07:05
  • On your window in WPF: make an event handler for `LocationChanged`. Then have that manually update the window (form) location. – Meirion Hughes Aug 07 '14 at 07:51
  • 1
    You can use a `WindowsFormsHost` control to display your WinForms Form as part of your WPF Application. Please see the [Walkthrough: Hosting a Windows Forms Control in WPF](http://msdn.microsoft.com/en-us/library/ms751761(v=vs.110).aspx) page on MSDN for further help. – Sheridan Aug 07 '14 at 07:52
  • 1) the form is called by a Page. Unfortunately there is no LocationChanged event handler for a page. But maybe I can catch that in the rearrange event. I just need to know which form was called by which page. 2) I tried using WindowsFormsHost, but I can not assign the page as owner and didn't succeed in calling form.ShowDialog – purbsel Aug 07 '14 at 08:32

0 Answers0