1

I am trying to implement Luke Quinane's answer on this question to work with Microsoft Access.

The code I am using is exactly what was posted in the answer, but I have put it below for convenience. Suffice to say, my Windows Form consists of a panel and a button:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Process p = Process.Start("MSACCESS.exe");
        p.WaitForInputIdle();
        SetParent(p.MainWindowHandle, panel1.Handle);

    }

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    private void Form1_Load(object sender, EventArgs e)
    {

    }
}

Microsoft Access launches fine, but then disappears whenever I try and place it inside the panel.

Whenever I replace MSACCESS.exe with notepad.exe, the program functions with Notepad as expected.

Is there something extra I need to do to get this procedure to work with Microsoft Access?

Community
  • 1
  • 1
Random Task
  • 121
  • 7
  • 1
    possible duplicate of [Is it possible to host a Microsoft Access form inside a .Net form?](http://stackoverflow.com/questions/11564626/is-it-possible-to-host-a-microsoft-access-form-inside-a-net-form) – Peter Jul 20 '12 at 15:13
  • Not really, I am asking a specific question about why this feature works with one application, and not with another – Random Task Jul 20 '12 at 15:15
  • 1
    Parenting a window from a different process is really hard to get right. Good luck. – David Heffernan Jul 20 '12 at 21:25
  • Thanks David, it turned out the instance of Access was launching on my Second monitor, but inside my panel, so I couldn't see it! – Random Task Jul 22 '12 at 14:32

0 Answers0