I am following this tutorial to create a custom control that inherits from one different than UserControl.
When opening the designer view of this control, instead of seeing a render of the control, I only see a black background with the message “To add components to your class, drag them from the Toolbox and use the Properties window to set their properties. To create methods and events for your class, switch to code view.”.
When adding the CustomControl to a form, the form’s designer renders the CustomControl as expected.
The custom control being rendered inside the form’s visual designer in Visual Studio
This is the code of my CustomControl:
public partial class CustomControl1 : Button
{
private int _counter = 0;
public CustomControl1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
// Draw the control
base.OnPaint(pe);
// Paint our string on top of it
pe.Graphics.DrawString($"Clicked {_counter} times", Font, Brushes.Purple, new PointF(3, 3));
}
protected override void OnClick(EventArgs e)
{
// Increase the counter and redraw the control
_counter++;
Invalidate();
// Call the base method to invoke the Click event
base.OnClick(e);
}
}
partial class CustomControl1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
SuspendLayout();
ResumeLayout(false);
}
#endregion
}
Is this a limitation of Visual Studio designer?
Do I need to change something in order to use see the control in the designer?