I am trying to extend the FlowLayoutPanel
class in Visual Studio to give it some functionality that it does not currently have. I am having issues extending it in such a manner that I can then select it in the toolbox and add it to another form.
The three methods I have tried are to simply just create a new class that subclasses FlowLayoutPanel
, also one that subclasses and then calls the : base()
constructor. When the application is built the subclass shows up in the toolbox but when I go to add it to a form it says "Failed to load toolbox item, it will be removed from the toolbox."
I have also tried to add a new UserControl
which I change its base class to FlowLayoutPanel
instead of UserControl
. After commenting out a line in the designer about AutoScaleMode
I can then build the application. Once I try to place the panel from the toolbox I receive the same error above.
How can I properly subclass FlowLayoutPanel
in Visual Studio so that I can use it from the toolbox?
EDIT:
Here is the entirety of my code, I added the OnPaint
override based on amura.cxg's answer and I still receive the same error.
I have cleaned, rebuilt, closed, and reopened VisualStudio to no avail. I have also copied amura.cxg's code exactly and used it, again the same issue.
using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace UserInterface.SubclassedControls
{
class TestLayoutPanel : FlowLayoutPanel
{
public TestLayoutPanel() /* : base() */
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
}
EDIT2:
I have made my class public and again cleaned, rebuilt, closed, and opened Visual Studio and still have the same issue. I have also tried to add the control to a "brand new" form with the same results.
using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace UserInterface.SubclassedControls
{
public class TestLayoutPanel : FlowLayoutPanel
{
public TestLayoutPanel() /* : base() */
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
}
EDIT3:
So as a sanity check I started a new VS project and subclassed FlowLayoutPanel
and added it to the default Form1
. I then went back to my current project and tried to create a simple new form class to see if my current form was having issues, but I still received the same error when trying to add the subclass FLP to it. I then tried a UserControl
that I made prior and have successfully added to other forms, which is now "broken" giving the same error message.
So what Project settings or Visual Studio settings could be preventing me from using these controls?