Note: I'm unfortunately restricted to .NET 1.1 for this application.
Workarounds involving .NET 2.0 are still interesting to me however, if
only because they may suggest a way forward...
I've got an application which acts as a wrapper for other plugins. The
plugins are UserControls which are hosted via SetParent calls, due to
living in separate app domains. They're all running within the same
thread, however.
I'm seeing the current issues:
1) Pressing tab to cycle focus around doesn't work within a plugin -
it appears to try to pull focus out into the "host" form, but will
never go *into* the plugin or cycle within the plugin
2) Drop-down lists don't respond properly to keyboard up/down (the
drop-down list just closes)
Now, I've been trying to work out how much of this is due to using
SetParent instead of adding the control "properly", and how much of it
is due to running in different AppDomains. The code below creates a
parent form with two textboxes, and a child control containing a
textbox and a dropdown. The behaviour I see with the example isn't
*quite* as bad as with different AppDomains, but it's still not
perfect:
1) Tab from the parent won't go into the child, it cycles between the
textboxes
2) Tab within the child goes from textbox to dropdown, but then won't
go anywhere else.
I'm hoping that solving the simpler set of issues will point to a
direction for the rest.
Any help very warmly welcome.
Thanks,
Jon
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
public class ParentForm : Form
{
[DllImport("User32.dll")]
protected static extern IntPtr SetParent(IntPtr hWndChild, IntPtr
hWndNewParent);
static void Main()
{
Application.Run (new ParentForm());
}
public ParentForm()
{
Size = new Size(400, 400);
TextBox tb = new TextBox();
tb.Location = new Point (5, 5);
tb.Text = "In parent";
tb.TabIndex = 1;
Controls.Add(tb);
tb = new TextBox();
tb.Location = new Point(5, 320);
tb.Text = "In parent";
tb.TabIndex = 3;
Controls.Add(tb);
}
protected override void OnHandleCreated(EventArgs e)
{
ChildControl child = new ChildControl();
child.TabIndex = 2;
child.Location = new Point(50, 50);
// Only have one of the following two lines uncommented;
// the first works, the second doesn't.
//Controls.Add(child);
SetParent(child.Handle, this.Handle);
}
}
public class ChildControl : UserControl
{
public ChildControl()
{
TextBox tb = new TextBox();
tb.Location = new Point(5, 5);
tb.Text = "Edit here";
Controls.Add(tb);
ComboBox cb = new ComboBox();
cb.Location = new Point(5, 50);
cb.DropDownStyle = ComboBoxStyle.DropDownList;
cb.Items.AddRange(new string[] {"First", "Second", "Third",
"Fourth"});
Controls.Add(cb);
Size = new Size(300, 300);
}
}