473,883 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
+ 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.W ebControls.Butt on.
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...

\\\
<DefaultValueAt tribute(GetType (Unit), "144px"), _
DescriptionAttr ibute("The width of the Cancel button.")> _
_
Public Overrides Property Width() As Web.UI.WebContr ols.Unit
Get
Return Me.Width
End Get
Set(ByVal Value As Web.UI.WebContr ols.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.StackOve rflowException was thrown.".

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

Does anyone have any ideas? Many thanks!!

Take care,

Marty
Nov 20 '05 #1
3 6770
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.Componen tModel
' Used with the Unit and Button types:
Imports System.Web.UI.W ebControls
..
..
..
Public Class myButton
Inherits Button

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

<CategoryAttrib ute("Applicatio n"), _
Browsable(True) , _
DescriptionAttr ibute("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******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

I have a control class that inherits from System.Web.UI.W ebControls.Butt on. 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...

\\\
<DefaultValueAt tribute(GetType (Unit), "144px"), _
DescriptionAttr ibute("The width of the Cancel button.")> _
_
Public Overrides Property Width() As Web.UI.WebContr ols.Unit
Get
Return Me.Width
End Get
Set(ByVal Value As Web.UI.WebContr ols.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.StackOve rflowException was thrown.".

I also tried to use the following line of code, but it barked about
requiring a constant expression:
<DefaultValueAt tribute(Unit.Pi xel(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("Y ouEventPropName "),DefaultPrope rty("YourPropNa me")

<DefaultPropert y("Width")> _
Public Class MyButton

'....

End Class

Ernest

"Marty McFly" <Ma***@Mc.Fly > wrote in message
news:#Q******** ******@TK2MSFTN GP09.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.Componen tModel
' Used with the Unit and Button types:
Imports System.Web.UI.W ebControls
.
.
.
Public Class myButton
Inherits Button

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

<CategoryAttrib ute("Applicatio n"), _
Browsable(True) , _
DescriptionAttr ibute("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******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

I have a control class that inherits from

System.Web.UI.W ebControls.Butt on.
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...

\\\
<DefaultValueAt tribute(GetType (Unit), "144px"), _
DescriptionAttr ibute("The width of the Cancel button.")> _
_
Public Overrides Property Width() As Web.UI.WebContr ols.Unit
Get
Return Me.Width
End Get
Set(ByVal Value As Web.UI.WebContr ols.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.StackOve rflowException was thrown.".

I also tried to use the following line of code, but it barked about
requiring a constant expression:
<DefaultValueAt tribute(Unit.Pi xel(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_BACKCOLO R As Color = _
Color.FromArgb( 212, 208, 200) ' Same as #D4D0C8.
Friend BUTTON_BACKCOLO R_ONFOCUS As Color = _
Color.FromArgb( 102, 255, 255) ' Same as #66FFFF.
Friend BUTTON_BACKCOLO R_ONBLUR As _
Color = Color.FromArgb( 212, 208, 200)
'///

'\\\
' The "CancelButt on" class.
Imports System.Web.UI.W ebControls
Imports System.Componen tModel
Imports System.Drawing

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

#Region " Initialization "

Inherits System.Web.UI.W ebControls.Butt on

Private Sub InitializeCompo nent()
' Initially set the overridden/shadowed properties,
' so they will appear as "default" values in the
' designer.
MyBase.Font.Siz e = FontUnit.XSmall
MyBase.Font.Nam e = "Verdana"
MyBase.Width = Unit.Pixel(BUTT ON_WIDTH)
MyBase.Height = Unit.Pixel(BUTT ON_HEIGHT)
End Sub

Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Init
InitializeCompo nent()
End Sub

#End Region

#Region " Properties "

Private _Text As String = "Cancel"
Private _Width As Unit = Unit.Pixel(BUTT ON_WIDTH)
Private _Height As Unit = Unit.Pixel(BUTT ON_HEIGHT)
Private _BackColor As Color = BUTTON_BACKCOLO R
Private _BackColorOnFoc us As Color = _
BUTTON_BACKCOLO R_ONFOCUS
Private _BackColorOnBlu r As Color = _
BUTTON_BACKCOLO R_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.BackColo r = _BackColor
End Set
End Property

<CategoryAttrib ute("Applicatio n"), _
Browsable(True) , _
DescriptionAttr ibute("The background color " & _
"when this button has focus.")> _
_
Public Property BackColorOnFocu s() As Color
Get
Return _BackColorOnFoc us
End Get
Set(ByVal Value As Color)
_BackColorOnFoc us = Value
End Set
End Property

<CategoryAttrib ute("Applicatio n"), _
Browsable(True) , _
DescriptionAttr ibute("The background color " & _
"when this button loses focus.")> _
_
Public Property BackColorOnBlur () As Color
Get
Return _BackColorOnBlu r
End Get
Set(ByVal Value As Color)
_BackColorOnBlu r = 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_Lo ad(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load

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

' Add cursor enhancements, converting WebControls.Col or
' type to an HTML RGB color string (ex: #FFFFFF).
Attributes.Add( "onfocus", "this.style.bac kground='" & _
ColorTranslator .ToHtml(_BackCo lorOnFocus) & "';")
Attributes.Add( "onblur", "this.style.bac kground='" & _
ColorTranslator .ToHtml(_BackCo lorOnBlur) & "';")

' 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******** ******@TK2MSFTN GP09.phx.gbl...
You should use attributes like those bellow, applied to the class .

DefaultEvent("Y ouEventPropName "),DefaultPrope rty("YourPropNa me")

<DefaultPropert y("Width")> _
Public Class MyButton

'....

End Class

Ernest

"Marty McFly" <Ma***@Mc.Fly > wrote in message
news:#Q******** ******@TK2MSFTN GP09.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.Componen tModel
' Used with the Unit and Button types:
Imports System.Web.UI.W ebControls
.
.
.
Public Class myButton
Inherits Button

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

<CategoryAttrib ute("Applicatio n"), _
Browsable(True) , _
DescriptionAttr ibute("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******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

I have a control class that inherits from

System.Web.UI.W ebControls.Butt on.
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...

\\\
<DefaultValueAt tribute(GetType (Unit), "144px"), _
DescriptionAttr ibute("The width of the Cancel button.")> _
_
Public Overrides Property Width() As Web.UI.WebContr ols.Unit
Get
Return Me.Width
End Get
Set(ByVal Value As Web.UI.WebContr ols.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.StackOve rflowException was thrown.".

I also tried to use the following line of code, but it barked about
requiring a constant expression:
<DefaultValueAt tribute(Unit.Pi xel(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
2774
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 at -1 and 0 respectively. Unless I specifically set the table field's defaultvalue to Null, the form comes up with an automatic value of 0 in the control? The control has NO default value property setting. Why is that?
18
18467
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 a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
9
2350
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 are set to the value of the last control. I found this link: http://www.codecomments.com/archive315-2005-1-366113.html which I think explains the situation but I'm not sure how to implement the solution in my case since I am not using a .ascx...
8
2271
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 happens. dim filt as string ... build filter string... UserControl.ReportFilter = filt
1
5262
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 host handles the event, validates the data and returns the validation results to the control by a callback to a control method, SetFooError(). All of that works great. If the host returns false on the validation, I display an error glyph next to...
6
7504
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. What I would like to do is when a new record is created in frmDemo I would like to set the CboTermID on the subform to a default value, say 1, without the user having to set focus on the subform and selecting an item from the combo box. Right now...
1
6525
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" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
7
6191
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 object with a new one while the second only replaces the Current object of C1.Cursor, but I can't
6
11096
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 how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
0
9942
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10749
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10857
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7974
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5801
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4618
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 we have to send another system
3
3236
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.