473,466 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Setting a default property for user control

Hello,

I have a control class that inherits from System.Web.UI.WebControls.Button.
When I drag this control from the "My User Controls" tab in the toolbox onto
the form, I want it to reflect the following default properties: Height =
32px, Width = 144px.

I declare the Width property in my control as...

\\\
<DefaultValueAttribute(GetType(Unit), "144px"), _
DescriptionAttribute("The width of the Cancel button.")> _
_
Public Overrides Property Width() As Web.UI.WebControls.Unit
Get
Return Me.Width
End Get
Set(ByVal Value As Web.UI.WebControls.Unit)
Me.Width = Value
End Set
End Property
///

After building the project, the Width in the Properties pane of the IDE is
disabled and displays the text: "Exception of type
System.StackOverflowException was thrown.".

I also tried to use the following line of code, but it barked about
requiring a constant expression:
<DefaultValueAttribute(Unit.Pixel(144)), _ ...

Does anyone have any ideas? Many thanks!!

Take care,

Marty
Nov 20 '05 #1
3 6703
Wow, nobody answering questions today? :-)

I finally came up with a VERY simple way to make the default values show up
in the designer. (I can't believe that I couldn't find something so basic
on MSDN or Google!) Hope this helps someone having the same problem!

Marty

\\\
' Used with property attributes:
Imports System.ComponentModel
' Used with the Unit and Button types:
Imports System.Web.UI.WebControls
..
..
..
Public Class myButton
Inherits Button

' The default width should be 144 pixels:
Private _Width As Unit = Unit.Pixel(144)

<CategoryAttribute("Application"), _
Browsable(True), _
DescriptionAttribute("The width (in pixels) of the button.")> _
_
Public Overrides Property Width() As Unit
Get
Return _Width
End Get
Set(ByVal Value As Unit)
_Width = Value
Me.Width = _Width
End Set
End Property
End Class
///
"Marty McFly" <Ma***@Mc.Fly> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the following default properties: Height =
32px, Width = 144px.

I declare the Width property in my control as...

\\\
<DefaultValueAttribute(GetType(Unit), "144px"), _
DescriptionAttribute("The width of the Cancel button.")> _
_
Public Overrides Property Width() As Web.UI.WebControls.Unit
Get
Return Me.Width
End Get
Set(ByVal Value As Web.UI.WebControls.Unit)
Me.Width = Value
End Set
End Property
///

After building the project, the Width in the Properties pane of the IDE is
disabled and displays the text: "Exception of type
System.StackOverflowException was thrown.".

I also tried to use the following line of code, but it barked about
requiring a constant expression:
<DefaultValueAttribute(Unit.Pixel(144)), _ ...

Does anyone have any ideas? Many thanks!!

Take care,

Marty

Nov 20 '05 #2
You should use attributes like those bellow, applied to the class .

DefaultEvent("YouEventPropName"),DefaultProperty(" YourPropName")

<DefaultProperty("Width")> _
Public Class MyButton

'....

End Class

Ernest

"Marty McFly" <Ma***@Mc.Fly> wrote in message
news:#Q**************@TK2MSFTNGP09.phx.gbl...
Wow, nobody answering questions today? :-)

I finally came up with a VERY simple way to make the default values show up in the designer. (I can't believe that I couldn't find something so basic
on MSDN or Google!) Hope this helps someone having the same problem!

Marty

\\\
' Used with property attributes:
Imports System.ComponentModel
' Used with the Unit and Button types:
Imports System.Web.UI.WebControls
.
.
.
Public Class myButton
Inherits Button

' The default width should be 144 pixels:
Private _Width As Unit = Unit.Pixel(144)

<CategoryAttribute("Application"), _
Browsable(True), _
DescriptionAttribute("The width (in pixels) of the button.")> _
_
Public Overrides Property Width() As Unit
Get
Return _Width
End Get
Set(ByVal Value As Unit)
_Width = Value
Me.Width = _Width
End Set
End Property
End Class
///
"Marty McFly" <Ma***@Mc.Fly> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have a control class that inherits from

System.Web.UI.WebControls.Button.
When I drag this control from the "My User Controls" tab in the toolbox

onto
the form, I want it to reflect the following default properties: Height = 32px, Width = 144px.

I declare the Width property in my control as...

\\\
<DefaultValueAttribute(GetType(Unit), "144px"), _
DescriptionAttribute("The width of the Cancel button.")> _
_
Public Overrides Property Width() As Web.UI.WebControls.Unit
Get
Return Me.Width
End Get
Set(ByVal Value As Web.UI.WebControls.Unit)
Me.Width = Value
End Set
End Property
///

After building the project, the Width in the Properties pane of the IDE is disabled and displays the text: "Exception of type
System.StackOverflowException was thrown.".

I also tried to use the following line of code, but it barked about
requiring a constant expression:
<DefaultValueAttribute(Unit.Pixel(144)), _ ...

Does anyone have any ideas? Many thanks!!

Take care,

Marty


Nov 20 '05 #3
Thank you for the reply, Ernest.

Actually, I was trying to give each property a default value that shows up
in the designer when adding the control, not assign a default event/property
to the parent class. The code I eventually came up with (that works) is
listed below.

Thanks again,

Marty

'\\\
' In the "Defaults" module...
Friend Const BUTTON_HEIGHT As Int16 = 32
Friend Const BUTTON_WIDTH As Int16 = 144
Friend BUTTON_BACKCOLOR As Color = _
Color.FromArgb(212, 208, 200) ' Same as #D4D0C8.
Friend BUTTON_BACKCOLOR_ONFOCUS As Color = _
Color.FromArgb(102, 255, 255) ' Same as #66FFFF.
Friend BUTTON_BACKCOLOR_ONBLUR As _
Color = Color.FromArgb(212, 208, 200)
'///

'\\\
' The "CancelButton" class.
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Drawing

<ToolboxBitmap(GetType(Button))> _
_
Public Class CancelButton

#Region " Initialization "

Inherits System.Web.UI.WebControls.Button

Private Sub InitializeComponent()
' Initially set the overridden/shadowed properties,
' so they will appear as "default" values in the
' designer.
MyBase.Font.Size = FontUnit.XSmall
MyBase.Font.Name = "Verdana"
MyBase.Width = Unit.Pixel(BUTTON_WIDTH)
MyBase.Height = Unit.Pixel(BUTTON_HEIGHT)
End Sub

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub

#End Region

#Region " Properties "

Private _Text As String = "Cancel"
Private _Width As Unit = Unit.Pixel(BUTTON_WIDTH)
Private _Height As Unit = Unit.Pixel(BUTTON_HEIGHT)
Private _BackColor As Color = BUTTON_BACKCOLOR
Private _BackColorOnFocus As Color = _
BUTTON_BACKCOLOR_ONFOCUS
Private _BackColorOnBlur As Color = _
BUTTON_BACKCOLOR_ONBLUR

Public Shadows Property Text() As String
Get
Return _Text
End Get
Set(ByVal Value As String)
_Text = Value
MyBase.Text = Value
End Set
End Property

Public Overrides Property Width() As Unit
Get
Return _Width
End Get
Set(ByVal Value As Unit)
_Width = Value
MyBase.Width = Value
End Set
End Property

Public Overrides Property Height() As Unit
Get
Return _Height
End Get
Set(ByVal Value As Unit)
_Height = Value
MyBase.Height = Value
End Set
End Property

Public Overrides Property BackColor() As Color
Get
Return _BackColor
End Get
Set(ByVal Value As Color)
_BackColor = Value
MyBase.BackColor = _BackColor
End Set
End Property

<CategoryAttribute("Application"), _
Browsable(True), _
DescriptionAttribute("The background color " & _
"when this button has focus.")> _
_
Public Property BackColorOnFocus() As Color
Get
Return _BackColorOnFocus
End Get
Set(ByVal Value As Color)
_BackColorOnFocus = Value
End Set
End Property

<CategoryAttribute("Application"), _
Browsable(True), _
DescriptionAttribute("The background color " & _
"when this button loses focus.")> _
_
Public Property BackColorOnBlur() As Color
Get
Return _BackColorOnBlur
End Get
Set(ByVal Value As Color)
_BackColorOnBlur = Value
End Set
End Property

Public Overrides ReadOnly Property Font() As FontInfo
Get
Return MyBase.Font
End Get
End Property

#End Region

Private Sub CancelButton_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

' Set the overridden/shadowed properties.
MyBase.Text = _Text
MyBase.Width = _Width
MyBase.Height = _Height
MyBase.BackColor = _BackColor

' Add cursor enhancements, converting WebControls.Color
' type to an HTML RGB color string (ex: #FFFFFF).
Attributes.Add("onfocus", "this.style.background='" & _
ColorTranslator.ToHtml(_BackColorOnFocus) & "';")
Attributes.Add("onblur", "this.style.background='" & _
ColorTranslator.ToHtml(_BackColorOnBlur) & "';")

' Add attribute to cancel the form.
Attributes.Add("onclick", _
"CancelEdit = true; myForm.submit;")

End Sub

End Class
'///
"Ernest Morariu" <er****@gesora.com> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
You should use attributes like those bellow, applied to the class .

DefaultEvent("YouEventPropName"),DefaultProperty(" YourPropName")

<DefaultProperty("Width")> _
Public Class MyButton

'....

End Class

Ernest

"Marty McFly" <Ma***@Mc.Fly> wrote in message
news:#Q**************@TK2MSFTNGP09.phx.gbl...
Wow, nobody answering questions today? :-)

I finally came up with a VERY simple way to make the default values show up
in the designer. (I can't believe that I couldn't find something so basic
on MSDN or Google!) Hope this helps someone having the same problem!

Marty

\\\
' Used with property attributes:
Imports System.ComponentModel
' Used with the Unit and Button types:
Imports System.Web.UI.WebControls
.
.
.
Public Class myButton
Inherits Button

' The default width should be 144 pixels:
Private _Width As Unit = Unit.Pixel(144)

<CategoryAttribute("Application"), _
Browsable(True), _
DescriptionAttribute("The width (in pixels) of the button.")> _
_
Public Overrides Property Width() As Unit
Get
Return _Width
End Get
Set(ByVal Value As Unit)
_Width = Value
Me.Width = _Width
End Set
End Property
End Class
///
"Marty McFly" <Ma***@Mc.Fly> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have a control class that inherits from

System.Web.UI.WebControls.Button.
When I drag this control from the "My User Controls" tab in the
toolbox onto
the form, I want it to reflect the following default properties:

Height = 32px, Width = 144px.

I declare the Width property in my control as...

\\\
<DefaultValueAttribute(GetType(Unit), "144px"), _
DescriptionAttribute("The width of the Cancel button.")> _
_
Public Overrides Property Width() As Web.UI.WebControls.Unit
Get
Return Me.Width
End Get
Set(ByVal Value As Web.UI.WebControls.Unit)
Me.Width = Value
End Set
End Property
///

After building the project, the Width in the Properties pane of the
IDE
is disabled and displays the text: "Exception of type
System.StackOverflowException was thrown.".

I also tried to use the following line of code, but it barked about
requiring a constant expression:
<DefaultValueAttribute(Unit.Pixel(144)), _ ...

Does anyone have any ideas? Many thanks!!

Take care,

Marty



Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
9
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
1
by: David Veeneman | last post by:
I am writing a control that relies on its host to validate the contents of one of its fields. The control fires a custom 'FooNeedsValidating' event and passes the field's data with the event. The...
6
by: Rick | last post by:
I have a main form called frmDemo with a subform frmStageTrack_Sub. On the subform is a Combo Box CboTermID. The frmDemo is tied to tblDemo and the frmStageTrack_Sub is tied to tblStageTrack. ...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
7
by: Academic | last post by:
What are the different effects of the following two statements: C1.Cursor = Cursors.WaitCursor C1.Cursor.Current = Cursors.WaitCursor I believe the first replaces the entire C1.Cursor...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.