newbie custom controls questions

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I'm writing a C# custom control and I have a couple of question regarding
its design-time behaviour:

1) how do I hide some of the control (not inherited) properties from the
designer? Some of the control properties are meaningful only at run-time, or
are just read-only, and I'd like them not to appear in the designer control
properties.

2) is there a way of painting the control differently according to whether
it is in run-time or design-time?

3) can you suggest any specific and relatively *advanced* (beyond the
basics) reading about developing custom controls with C#?

Thanks guys!
 
Dan,

For properties that you don't want appear in the Properties window, you
can place the Browsable attribute on them, passing false to the constructor,
and the PropertyGrid will not show those properties.

If you want to paint the control differently at design time as opposed
to run time, then check the DesignMode property on the Control class. It is
inherited from the Component class and will return true if the control is
currently in design mode.

As for developing custom controls with C#, I would recommend any book on
advanced control creation. Basically, you are going to use the same
principles (with modifications) for creating custom controls (windows
message handling, drawing, state management, etc, etc) in any language.

Hope this helps.
 
Hi Dan,

Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.
Based on my understanding, you have 3 problems on design-time, I will help
you one by one.

===================================================
1). There is an attribute BrowsableAttribute in System.ComponentModel
namespace, that can be specified on a property. It can control the
visibility of the property in a Properties window. So you can hide your
property like this:
[Browsable(false)]
public int MyProperty {
get {
// Insert code here.
return 0;
}
set {
// Insert code here.
}
}

2). Normally, the ControlDesigner class control the design-time behavior of
the control.

Is your custom control a WinForm control or Web Form control?(There are
System.Windows.Forms.Design.ControlDesigner and
System.Web.UI.Design.ControlDesigner, each for WinForm control and Web Form
control)

For web form control at design-time, the designer will default use the html
that the control will renderred(The html in render method) to show the
design-time look.
You can specify a your customized ControlDesigner class on you
control(Through DesignerAttribute), then override the
ControlDesigner.GetDesignTimeHtml method to specify the design-time look
html code.

For WinForm, the designer will just use the run-time look of the control.
But there are also many protected methods of ControlDesigner, which you can
override and change the default behavior of your control.(Actually, the
designer hook the control message through WindowProc)

In your code, you can determine whether it is design-time or runtime
through Control.DesignMode property(Which inherit from Component.DesignMode)

3). "Developing custom controls with C#" is a big and common topic, based
on your questions in this post, I think more you want are the "Advanced"
design-time articles of control development.
Acutally, VS.net exposes many facilities that allow components to take
advantage of the designer architecture in VS .NET. These design-time
supports are mainly getting done through many design related attribute.

For good resource and reference, the shawn burke's articles may help you
much:

To manipulate your control to interactive well with property browser:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/vsnetpropbrow.asp
(Make Your Components Really RAD with Visual Studio .NET Property Browser)

To make your control more designable:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/pdc_vsdescmp.asp
(Creating Designable Components for Microsoft Visual Studio .NET Designers)

To write a more customized design for your component:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/custdsgnrdotnet.asp
(Writing Custom Designers for .NET Components)

====================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top