All, I have the a custom user control which is invoked using a singleton pattern. This control can be shown or hidden and to update the UI (to provide a show/hide control option) I set up an event handler in the controls constructor.
this.VisibleChanged += new EventHandler(ResultsControl_VisibleChanged);
and the event handler is
void ResultsControl_VisibleChanged(object sender, EventArgs e)
{
// Get reference to Show/Hide button.
var showHideResults = ((SqlEditorForm)this.ParentForm).ShowHideResultsButton;
if (instance != null)
showHideResults.Enabled = true;
// Change the status.
showHideResults.Text = this.Visible ?
"&Hide Query Results" :
"&Show Query Results";
showHideResults.Image = this.Visible ?
Properties.Resources.HideResultsVS201224 :
Properties.Resources.ShowResultsVS201224;
}
The problem is with the way I am getting the reference to the ShowHideResultsButton. I am getting the following error thrown from the designer…

What am I doing wrong here?
Thanks for your time.
Edit. I seem to have solved this by moving the
this.VisibleChanged += new EventHandler(ResultsControl_VisibleChanged);
from the constructor to the controls Load event. So the question now becomes: is this a valid fix?
At the moment when you are designing your
UserControlyou don’t have a reference to theSqlEditorForm. It’sParentFormproperty will becomeSqlEditorFormonly when you put yourResultsControlon theSqlEditorFormeither using designer or by code. Until then IDE only knows that it is of type Form. Why don’t you implement yourResultsControl_VisibleChangedevent handler withinSqlEditorForm?