Custom WYSIWYG editor - wait for WinForms to close and then import file

Hi,

I’m trying to develop a custom WYSIWYG editor to use in Dynamics Nav 2009 R2. I need to store a HTML source (item description) in a BLOB field.

What I’ve done by now:

I’ve created a DLL which I use to show a custom Windows.Forms.Form control that contains a WebBrowser control in which I’m running a CKEditor. Everything works great.

I’ve created a codeunit which I use to export the contents of my BLOB field to a temporary file, which contents I then import to my wysiwyg editor inside WebBrowser control. Until now - everythings fine. The problem descriped below.

What I don’t know how to do:

Inside my codeunit I’m running MyDll.ShowForm(). I would like it (codeunit) to somehow wait until the my windows form closes, and then continue execution.

How my codeunit looks like:

BEGIN

  IF ISCLEAR(MyDll) THEN
  BEGIN
    IF NOT CREATE(MyDll) THEN
    BEGIN
      ERROR('DLL not available');
    END;
  END;

  Item.CALCFIELDS("Webstore Description");
  tempFilePath := 'C:\Temp\__nav_ws_desc.bin';
  editorUrl := 'path_to_editor_html_page';

  IF FILE.EXISTS(tempFilePath) THEN
  BEGIN
    //FILE.ERASE(tempFilePath);
  END;

  //Read BLOB contents
  IF Item."Webstore Description".HASVALUE THEN
  BEGIN
    Item."Webstore Description".EXPORT(tempFilePath);
  END
  ELSE BEGIN MESSAGE(Item."No."); END;

  MyDll.EditorUrl(editorUrl);
  MyDll.FilePath(tempFilePath);
  MyDll.Title(Item."No." + ' ' +Item.Description);

  MyDll.ShowForm();

// here I would like the codeunit to wait for MyDll.Close() before executing further.

//Save BLOB contents
  IF FILE.EXISTS(tempFilePath) THEN
  BEGIN
     Item."Webstore Description".IMPORT(tempFilePath);
    //FILE.ERASE(tempFilePath);
  END
  ELSE BEGIN MESSAGE('file not found'); END;

  Item.MODIFY;
  CLEAR(MyDll);
END;

Is there some kind of event or trigger that I can use?

Any hints will be very much appreciated.

Thanks in advance,

Michal.