Custom Button Control

  • Thread starter Wimpie van Lingen
  • Start date
W

Wimpie van Lingen

Hi

I've created a control that inherits from the button control. The control
has one additional property called ButtonType which can be set to Ok,
Cancel, New, Edit, etc. When the ButtonType property changes, the Image,
Text, TextAlignment, etc. properties are changed for the control.

What happens is that when I put the control on a form and I set the
ButtonType property, all the fields that are changed are then highlighted as
changed and written in the Form.Designer.vb file to initialize those
properties. How can I prevent this from happening?

At the moment, the following is written:
Me.DialogButton1.Location = New System.Drawing.Point(359, 133)
Me.DialogButton1.Cursor = System.Windows.Forms.Cursors.Hand
Me.DialogButton1.ButtonType = ButtonTypeEnum.Arrow_Next
Me.DialogButton1.Font = New System.Drawing.Font("Tahoma", 9.0!)
Me.DialogButton1.Image =
CType(resources.GetObject("DialogButton1.Image"), System.Drawing.Image)
Me.DialogButton1.ImageAlign =
System.Drawing.ContentAlignment.MiddleRight
Me.DialogButton1.MaximumSize = New System.Drawing.Size(90, 28)
Me.DialogButton1.MinimumSize = New System.Drawing.Size(90, 28)
Me.DialogButton1.Size = New System.Drawing.Size(90, 28)
Me.DialogButton1.Text = "&Next "
Me.DialogButton1.TextAlign = ContentAlignment.MiddleRight
Me.DialogButton1.TextImageRelation =
TextImageRelation.TextBeforeImage
Me.DialogButton1.Name = "DialogButton1"


Basically most of those properties are already set when the control is
created or when the ButtonType property is set. So basically all I want to
appear in the form designer is:

Me.DialogButton1.Location = New System.Drawing.Point(359, 133)
Me.DialogButton1.ButtonType = ButtonTypeEnum.Arrow_Next
Me.DialogButton1.Name = "DialogButton1"


Any ideas how I can do that?

Regards

Wimpie
 
P

Phill W.

Wimpie said:
What happens is that when I put the control on a form and I set the
ButtonType property, all the fields that are changed are then highlighted as
changed and written in the Form.Designer.vb file to initialize those
properties. How can I prevent this from happening?

Welcome to the Wonderful World of Attributes.

To prevent the properties being considered as "changed" (and, therefore,
showing up as Bold), apply a DefaultValueAttribute to them (you may need
to override/shadow each Property before you can do this):

Imports System.ComponentModel

<DefaultValue("&Next")> _
Property Text() as String


If you want to prevent the property appearing in the properties window
at all, then you can do that too.

<Browsable(False)> _
Property Text() as String

*But* the Designer will /still/ write the code to set this property.
If you want to prevent this (and, IMHO, this is a Good Idea while you're
still developing your inherited Control), use this Attribute to tell it
not to:

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden))> _
Property Text() as String

So you wind up with combinations like this - for the stuff other
Developers can play with ...

<Browsable(True) _
, Category("Whizzo Stuff") _
, DefaultValue("(None)") _
, DesignerSerializationVisibility(Visible) _
Property Text() as String

.... and ...

<Browsable(False) _
, Category("Hidden Stuff") _
, DefaultValue("Some Value") _
, DesignerSerializationVisibility(Hidden) _
Property HiddenP() as String

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top