A set of .NET Framework managed libraries for developing graphical user interfaces.
ControlDesigner code not being called
Using VS2022 17.2.6 .Net framework 4.8.04162. C#
Migrating from VS2005; My custom UserControl with custom ControlDesigner is not working in DesignMode. That is, the ControlDesigner
code is not functioning.
Debugging the problem I have created a simple control using an example from MS Help Viewer.
The ControlDesigner code does not appear to be called in sample designer code copied straight from MS Help Viewer.
I have managed to get the debugger to run during design mode by creating a separate VS2022 process an the Attaching to the target process.
When I open the form which contains the test control in the target process, the debugger will break on code in the test control, ie OnPaint(), but the debugger will not break on code in the ExampleControlDesigner; ie. OnMouseEnter() or OutlineColor.Set.
Can someone help with why ControlDesigner code is not be called?
If you need specific VS 2022 info, please tell me where to find it since I am new to this environment.
Here is the code from MS Help VIewer
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace ControlDesignerExample
{
// ExampleControlDesigner is an example control designer that
// demonstrates basic functions of a ControlDesigner.
public class ExampleControlDesigner : System.Windows.Forms.Design.ControlDesigner
{
// This Boolean state reflects whether the mouse is over the control.
private bool mouseover = false;
// This color is a private field for the OutlineColor property.
private Color lineColor = Color.White;
// This color is used to outline the control when the mouse is
// over the control.
public Color OutlineColor
{
get
{
return lineColor;
}
set
{
lineColor = value; // Set break point here; Doesn't hit
}
}
public ExampleControlDesigner()
{
}
// Sets a value and refreshes the control's display when the
// mouse position enters the area of the control.
protected override void OnMouseEnter()
{
this.mouseover = true; // Set break point here; doesn't hit
this.Control.Refresh();
}
// Sets a value and refreshes the control's display when the
// mouse position enters the area of the control.
protected override void OnMouseLeave()
{
this.mouseover = false;
this.Control.Refresh();
}
// Draws an outline around the control when the mouse is
// over the control.
protected override void OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe)
{
if (this.mouseover)
{
pe.Graphics.DrawRectangle(
new Pen(new SolidBrush(this.lineColor), 6),
0,
0,
this.Control.Size.Width,
this.Control.Size.Height);
}
}
// Adds a property to this designer's control at design time
// that indicates the outline color to use.
// The DesignOnlyAttribute ensures that the OutlineColor
// property is not serialized by the designer.
protected override void PreFilterProperties(System.Collections.IDictionary properties)
{
PropertyDescriptor pd = TypeDescriptor.CreateProperty(
typeof(ExampleControlDesigner),
"OutlineColor",
typeof(System.Drawing.Color),
new Attribute[] { new DesignOnlyAttribute(true) });
properties.Add("OutlineColor", pd);
}
}
// This example control demonstrates the ExampleControlDesigner.
[DesignerAttribute(typeof(ExampleControlDesigner))]
public class ExampleControl : System.Windows.Forms.UserControl
{
private System.ComponentModel.Container components = null;
public ExampleControl()
{
components = new System.ComponentModel.Container();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
}
}