Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Custom Button not showing up in Designer
 

Custom Button not showing up in Designer

Hi!

I want to crteate a custom control. (just for testing a button)

Here is what i did:
1) created a 'WindowsFormsControlLibrary' project
2) deleted 'UserControl1.cs'
3) added a 'CustomControl'
4) changed base class from 'Control' to 'Button'
5) now if i switch to design view from code view, all i see is a gray layout with a text "To Add Components to your class, drag ... etc"
instead of a button

Of Course, if i compile the project and add the dll to a winfows forms project,i see it.
But what i want is to visually edit the custom control in the control library project.

Does someone know how to let the button show up in the design view?
PoInTeRkInG  Saturday, September 12, 2009 1:48 PM
Hi,

It is impossible to visually edit the component control that is inherited from base control. Only the user control can be edited visually. But whereas component control by programmatically for visual effects

Good Luck.


Impossible is such a widely misused word ;).

Why you would want to visually edit a button class without hosting it on a container controlis beyond me, but if that's what you want to do then it's fairly simple.

You need to inherit from a control which has hijacked the usercontrol designer.

Note that not all controls can use this method, but most can.
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;

namespace DesignableControls
{
    [ToolboxItem(true)]
    public class MyButton : MyButtonBase
    {
        public MyButton() : base()
        {
            InitializeComponent();
        }

        public void InitializeComponent()
        {
        } 
    }

    [Designer("System.Windows.Forms.Design.UserControlDocumentDesigner, System.Design", typeof(IRootDesigner))]
    [ToolboxItem(false)]
    public class MyButtonBase : Button
    {
    }
}<br/><br/>
MyButton needs to be defined as the first class in this file and it also needs the constructor and initializeComponent() method defined so that any changes are serialized.
Mick Doherty
http://dotnetrix.co.uk
  • Marked As Answer byPoInTeRkInG Sunday, September 13, 2009 1:34 PM
  •  
Mick Doherty  Sunday, September 13, 2009 10:54 AM
Hi,

It is impossible to visually edit the component control that is inherited from base control. Only the user control can be edited visually. But whereas component control by programmatically for visual effects

Good Luck.

Malik M.Shahid  Saturday, September 12, 2009 9:25 PM
Hi,

It is impossible to visually edit the component control that is inherited from base control. Only the user control can be edited visually. But whereas component control by programmatically for visual effects

Good Luck.


Impossible is such a widely misused word ;).

Why you would want to visually edit a button class without hosting it on a container controlis beyond me, but if that's what you want to do then it's fairly simple.

You need to inherit from a control which has hijacked the usercontrol designer.

Note that not all controls can use this method, but most can.
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;

namespace DesignableControls
{
    [ToolboxItem(true)]
    public class MyButton : MyButtonBase
    {
        public MyButton() : base()
        {
            InitializeComponent();
        }

        public void InitializeComponent()
        {
        } 
    }

    [Designer("System.Windows.Forms.Design.UserControlDocumentDesigner, System.Design", typeof(IRootDesigner))]
    [ToolboxItem(false)]
    public class MyButtonBase : Button
    {
    }
}<br/><br/>
MyButton needs to be defined as the first class in this file and it also needs the constructor and initializeComponent() method defined so that any changes are serialized.
Mick Doherty
http://dotnetrix.co.uk
  • Marked As Answer byPoInTeRkInG Sunday, September 13, 2009 1:34 PM
  •  
Mick Doherty  Sunday, September 13, 2009 10:54 AM
Thx, that was exactly what i needed.
PoInTeRkInG  Sunday, September 13, 2009 1:32 PM

You can use google to search for other answers

Custom Search

More Threads

• Buttons in form's titlebar
• VS2005's Form Designer can't find the event's handler if defined in parents class. (VS2003 works)
• Why the designer does not detach event handlers
• Debug vs Release
• How to implement Datasource property on custom controls?
• Form lost objects in design window
• Popup window
• Composite Control and Click Event
• listbox ownerdraw doesn't redraw when multiselect is on
• pls help: Resize control at runtime?