MICROSOFT : Required Designer Attributes ...
Messages   Related Types
This message was discovered on ASPFriends.com 'winforms-cs' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Michel Comeau (VIP)
Ok, i know its gonna sound stupid, but i need to know what to add as
attributes for a subclassed button to show in the ToolBox.

If i create a UserControl its showing there, but not if i subclass from
Button.

What is the trick, cuz the docs dont show me what i need to do.

Here is the sample:

--------------- Full Class Code ----------------------
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Windows.Forms.ComponentModel;

namespace EroBooking.Components
{
    /// <summary>
    /// Summary description for ArrowButton.
    /// </summary>
    [
        ToolboxItem(true)
    ]
    public class ArrowButton : Button
    {
        private bool _dirty;

        public enum ArrowDirection
        {
            Top, Bottom, Left, Right
        }

        public ArrowButton()
        {
            _dirty = true;
        }

        protected override void OnResize(System.EventArgs e)
        {
            _dirty = true;
            base.OnResize(e);
        }

        /// <summary>
        /// Rebuilds the Image of the Arrow base on the size of
the button
        /// </summary>
        protected void BuildArrowImage(Graphics g)
        {
        Bitmap bmp = new Bitmap(ClientSize.Width,
ClientSize.Height, g);
        Graphics g2 = Graphics.FromImage(bmp);

            // Cleanup previously stored Image
            if (this.Image != null)
            {
                this.Image.Dispose();
                this.Image = null;
            }

            // Create a new Image
            this.Image = bmp;
            g2.FillRectangle(new SolidBrush(this.BackColor),
ClientRectangle);
            ControlPaint.DrawScrollButton(g2,
ClientRectangle, ScrollButton.Left, ButtonState.Flat);
            g2.Dispose();
        }

        protected override void
OnPaint(System.Windows.Forms.PaintEventArgs pevent)
        {
            if (_dirty)
            {
                BuildArrowImage(pevent.Graphics);
                _dirty = false;
            }
            base.OnPaint(pevent);
        }
    }
}

----------- End of Class Code -----------------

Michel C.

Reply to this message...
 
    
Paul D. Murphy
/*Code Comment numbers
*=20
I: The toolbar item attribute in the code below
=20
This attribute is correct. It is basically what
you need to show the class in the toolbox. The
default value is true, so even if you leave off
the attribute by design the control will still show
in the tool box. Most of the attributes default to
some value.
=20
II: The attributes you are missing
=20
There are a handful, each with different properties. Three
of
these that are relevant to your situation:
=20
Designer Attribute
[Designer(typeof(<SOME_TYPE>),
typeof(<SOME_INTERFACE>))]
=20
Type Converter Attribute
[TypeConverter(<SOME_TYPE>)]
=20
Filter Toolbox Item Attribute
[ToolboxItemFilter(<SOME_NAMESPACE[?I think there are
other ways to pull it of like via a type]>, <SOME_ENUM>)]
=20
=20
Information on how to operate the first two can be found in
the
documentation here:
=20
ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconenhancingdesign-tmesupport
.htm
=20
For information on a complete implementation in the context
of a component you can read this article.=20
I would really recommend you read it, because it defines
everything that you 'can' do with=20
the component designer architecture. This is pretty critical
as three major players in .NET work off this=20
technology (Winforms, WebForms, and Abstract Designers).
=20
Winforms and WebForms make a lot of sense, but the one that
is the crucial piece in the .NET
pie is Abstract Designers. Abstract Designers are not really
talked about that much, but the
system as a whole hinges on them. Microsoft has a lot more
in store for us that just Visual Studio
that uses the abstract designers. This is just my
speculation here, and I'm almost ranting, but I believe
from reading everything I can about Windows.NET that the
component designer architecture is=20
going to be the basis for the Windows.NET compound document
architecture. It meets all of the
obvious design goals that can be inferred from the concept
of a single window interface. And what looks
like the root interface (IDesignerHost) meets the obvious
goals for multiple designers playing well with=20
each other.
Enough of that. Back to Visual Studio.
=20
Because VS.NET uses these interfaces for Abstract Designers
internally you can get a handle on them
in code. This is how you perform the complicated toolbox
inserts on load, icon mapping and some
other more advanced features that get dealt with the in the
context of the DesignerAttribute.
=20
Your enumeration problem would be a hack around the bug, but
it could be achieved be placing a custom type converter
on the enumeration. VS.NET (The abstract designer) would
then convert your property in and out
like you see fit to one of three representations (a string
value, a drop down list, or a WinForm [?I think]).
=20
*/
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Windows.Forms.ComponentModel;
=20
namespace EroBooking.Components
{
/// <summary>
/// Summary description for ArrowButton.
/// </summary>
=20
=20
//
// I: the toolbar item attribute
//
[
ToolboxItem(true)
]
//
// II: the attributes you are missing
//
public class ArrowButton : Button
{
private bool _dirty;
=20
public enum ArrowDirection
{
Top, Bottom, Left, Right
}
=20
public ArrowButton()
{
_dirty =3D true;
}
=20
protected override void OnResize(System.EventArgs e)
{
_dirty =3D true;
base.OnResize(e);
}
=20
=20
=20
/// <summary>
/// Rebuilds the Image of the Arrow base on the size of the
button
/// </summary>
protected void BuildArrowImage(Graphics g)
{
Bitmap bmp =3D new Bitmap(ClientSize.Width,
ClientSize.Height, g);
Graphics g2 =3D Graphics.FromImage(bmp);
=20
// Cleanup previously stored Image
if (this.Image !=3D null)
{
this.Image.Dispose();
this.Image =3D null;
}
=20
// Create a new Image
this.Image =3D bmp;
g2.FillRectangle(new SolidBrush(this.BackColor),
ClientRectangle);
ControlPaint.DrawScrollButton(g2,
ClientRectangle, ScrollButton.Left,
ButtonState.Flat);
g2.Dispose();
}
=20
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs pevent)
{
if (_dirty)
{
BuildArrowImage(pevent.Graphics);
_dirty =3D false;
}
base.OnPaint(pevent);
}
}
}
=20

Reply to this message...
 
    
dulovits martin
Could you please post a working version of your arrowbutton. I ve exactly the same Problem but didnt succeed till now.

I tried it like that ..

namespace EroBooking.Components
{
/// <summary>
/// Summary description for ArrowButton.
/// </summary>
[
ToolboxItem(true)
]
[
Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design",
typeof(System.ComponentModel.Design.IDesigner))
]
[
TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))
]
[
ToolboxItemFilter("System.Windows.Forms")
]

public class ArrowButton : Button
{
private bool _dirty;

thx in advance ..
Reply to this message...
 
 
System.ComponentModel.Design.IDesigner
System.ComponentModel.Design.IDesignerHost
System.ComponentModel.DesignerAttribute
System.ComponentModel.ExpandableObjectConverter
System.ComponentModel.TypeConverter
System.ComponentModel.TypeConverterAttribute
System.Drawing.Bitmap
System.Drawing.Design.ToolboxItem
System.Drawing.Graphics
System.Drawing.Image
System.Drawing.SolidBrush
System.EventArgs
System.Web.UI.UserControl
System.Web.UI.WebControls.Image
System.Windows.Forms.ButtonState
System.Windows.Forms.ControlPaint
System.Windows.Forms.Design.ParentControlDesigner
System.Windows.Forms.PaintEventArgs
System.Windows.Forms.ScrollButton
System.Windows.Forms.UserControl




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com