private Button CreateAutomationAccessButton()
{
// When we unit test from automation, no mouse or keyboard events
// are triggered. The problem with this is that the status of commands
// are never re-queried. We make this button available to the unit
// test system so that the unit test can force an immediate requery.
var result = new Button
{
Name = AutomationAccessButtonName,
Text = AutomationAccessButtonName,
Visible = false
};
((NiEnv)GetService(typeof(INiEnv))).MainForm.Controls.Add(result);
var handle = result.Handle;
result.Click += (s, e) => OnRequerySuggested(EventArgs.Empty);
return result;
}