if I have a property something like :
[DefaultValue(0)]
public int Width
{
get {return m_width}
set {m_width = value}
}
As a calling program/routine how can I set m_width back to it's default value 0 without knowing that it is 0
i.e. something like this.Width = Width.DefaultVa lue rather than this.Width = 0
Thanks,
Steve 7 7397
The DefaultValue attribute is there for the benefit of the PropertyGrid as
used in design time mode. The grid reads the attribute using reflection to
obtain the default value and provides the user with an option to "reset" the
value.
You could use a similar scheme to read the attributes of any given property
and see if it had a default value attribute. Then, if it does, force the
property to the value.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"steve bull" <bu****@comcast .net> wrote in message
news:w3******** *************** ***@4ax.com... if I have a property something like :
[DefaultValue(0)] public int Width { get {return m_width} set {m_width = value} }
As a calling program/routine how can I set m_width back to it's default value 0 without knowing that it is 0
i.e. something like this.Width = Width.DefaultVa lue rather than this.Width = 0
Thanks,
Steve
DefaultValue does not set the value of your property.
It is used for the property-sheet. So you can click the Reset button Then
the default values are set.
Try to set the DefaultValue other than 0. And you'll see.
"steve bull" wrote: if I have a property something like :
[DefaultValue(0)] public int Width { get {return m_width} set {m_width = value} }
As a calling program/routine how can I set m_width back to it's default value 0 without knowing that it is 0
i.e. something like this.Width = Width.DefaultVa lue rather than this.Width = 0
Thanks,
Steve
I got the following code from MSDN:
// Gets the attributes for the property.
AttributeCollec tion attributes = TypeDescriptor. GetProperties
(this)"MyProper ty"].Attributes;
/* Prints the default value by retrieving the DefaultValueAtt ribute
* from the AttributeCollec tion. */
DefaultValueAtt ribute myAttribute =
(DefaultValueAt tribute)attribu tes[typeof(DefaultV alueAttribute)];
Console.WriteLi ne("The default value is: " + myAttribute.Val ue.ToString());
You can use the myAttribute.Val ue to set the your property to the default
value.
"steve bull" wrote: if I have a property something like :
[DefaultValue(0)] public int Width { get {return m_width} set {m_width = value} }
As a calling program/routine how can I set m_width back to it's default value 0 without knowing that it is 0
i.e. something like this.Width = Width.DefaultVa lue rather than this.Width = 0
Thanks,
Steve
The DefaultValue attribute is there for the benefit of the PropertyGrid as
used in design time mode. The grid reads the attribute using reflection to
obtain the default value and provides the user with an option to "reset" the
value.
You could use a similar scheme to read the attributes of any given property
and see if it had a default value attribute. Then, if it does, force the
property to the value.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"steve bull" <bu****@comcast .net> wrote in message
news:w3******** *************** ***@4ax.com... if I have a property something like :
[DefaultValue(0)] public int Width { get {return m_width} set {m_width = value} }
As a calling program/routine how can I set m_width back to it's default value 0 without knowing that it is 0
i.e. something like this.Width = Width.DefaultVa lue rather than this.Width = 0
Thanks,
Steve
DefaultValue does not set the value of your property.
It is used for the property-sheet. So you can click the Reset button Then
the default values are set.
Try to set the DefaultValue other than 0. And you'll see.
"steve bull" wrote: if I have a property something like :
[DefaultValue(0)] public int Width { get {return m_width} set {m_width = value} }
As a calling program/routine how can I set m_width back to it's default value 0 without knowing that it is 0
i.e. something like this.Width = Width.DefaultVa lue rather than this.Width = 0
Thanks,
Steve
I got the following code from MSDN:
// Gets the attributes for the property.
AttributeCollec tion attributes = TypeDescriptor. GetProperties
(this)"MyProper ty"].Attributes;
/* Prints the default value by retrieving the DefaultValueAtt ribute
* from the AttributeCollec tion. */
DefaultValueAtt ribute myAttribute =
(DefaultValueAt tribute)attribu tes[typeof(DefaultV alueAttribute)];
Console.WriteLi ne("The default value is: " + myAttribute.Val ue.ToString());
You can use the myAttribute.Val ue to set the your property to the default
value.
"steve bull" wrote: if I have a property something like :
[DefaultValue(0)] public int Width { get {return m_width} set {m_width = value} }
As a calling program/routine how can I set m_width back to it's default value 0 without knowing that it is 0
i.e. something like this.Width = Width.DefaultVa lue rather than this.Width = 0
Thanks,
Steve
thanks, I will give it a try
Steve
On Wed, 29 Jun 2005 23:37:02 -0700, Marinus Holkema <Ma************ @discussions.mi crosoft.com> wrote: I got the following code from MSDN:
// Gets the attributes for the property. AttributeCollec tion attributes = TypeDescriptor. GetProperties (this)"MyProper ty"].Attributes;
/* Prints the default value by retrieving the DefaultValueAtt ribute * from the AttributeCollec tion. */ DefaultValueAtt ribute myAttribute = (DefaultValueAt tribute)attribu tes[typeof(DefaultV alueAttribute)]; Console.WriteLi ne("The default value is: " + myAttribute.Val ue.ToString());
You can use the myAttribute.Val ue to set the your property to the default value.
"steve bull" wrote:
if I have a property something like :
[DefaultValue(0)] public int Width { get {return m_width} set {m_width = value} }
As a calling program/routine how can I set m_width back to it's default value 0 without knowing that it is 0
i.e. something like this.Width = Width.DefaultVa lue rather than this.Width = 0
Thanks,
Steve
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shabam |
last post by:
I have a text field that's pre-filled with data. Suppose the user edits it,
but decides he wants to reset the data back to the original pre-filled data,
how can I do that?
|
by: Matt |
last post by:
i need to implement a clear button to clear all the fields in the
form,
but i am thinking i can just use reset button.
<input type="reset" name="reset" value="CLEAR">
The first thought is that if there is default value reset and clear
will become different.
My understanding is that reset means to restore the original page
before
|
by: Ryan Stewart |
last post by:
Is there a way to reset the style property of an HTML element to some default or
to all empty values? I have a group of elements whose style settings may be
changed arbitrarily at certain points in a script (maybe set the background
color and font weight of one element and the text align of another), but at
another point I want to undo all of these changes and go back to the original
state (which is actually all empty styles). Is there a...
|
by: Nathan Sokalski |
last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an event is fired by one of the controls contained in the User Control, these variable are reset. Here is my current code (I have a little more to add later, right now I am just concerned about the variables getting reset):
Public Class DatePicker2...
|
by: Lance |
last post by:
I want to be able to reset a complex property in a PropertyGrid. I know that for properties that are ValueTypes you can include System.ComponentModel.DefaultValue in the declaration of the property. But, for complex property types (e.g., instance types) this does not work because System.ComponentModel.DefaultValue requires a constant value
In order to indicate if a property should be serialized you can include a boolean function named...
| |
by: Kd |
last post by:
I have the following set up to give me aresponse number R05-001
I would like it to reset to R06-001 at new year
ResponseNo: "R" & Right(Format(Date(),"yyyy"),2) & "-" &
Format(,"000")
This is an expression in a query
any help is apprecieated
Ken
|
by: TD |
last post by:
I've read several posts here that say global variables are reset
whenever an unhandled error occurs. I want to use a custom form
property instead of a global variable to store a boolean value. My
question is does a custom form property get reset also? Was also
wondering if there is any reason one would ever use a global variable
since the consensus seems to be to never use global variables?
|
by: newbie |
last post by:
i have a form in which a hidden field (initial value as '0', and my
javascript set it to '1' when an event is trigged).
In the same form, i have a reset field. But I realized that the hidden
field is not reset to '0' when i push the
reset button. If I simply change the node from
"<input type="hidden" id='IsChanged' value='0'>"
to
"<input type="text" id='IsChanged' value='0'>"
Everything is working as expected (the value is reset to '0'...
|
by: artev |
last post by:
if in a page I have a search form and I want use the method reset()
for reinsert the default values, I notice that after a research, for
the method reset(), the default values aren't more that first time loaded
in the form but that of the form set for the search (I think so);
see that the form is inner the same result's page, pheraphs
the reset() 'see' how default values only the last form and not those
that is loaded initially;
|
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...
|
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...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |