473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Set DefaultValue property attribute to non constant value.

Hi, I would like to set the default value of a property on my control by:
[System.ComponentModel.DefaultValue( typeof(Color),
SystemColors.WindowText.ToString() )]

but can't because SystemColors.WindowText is not a constant. Microsoft
controls do it, can I - is there a work round?

I can cheat by...
[System.ComponentModel.DefaultValue(typeof(Color), "Black")]

but its not quite what I want. Plus: if I use the cheat("Black") would this
have any problems with internationalisation - would the control work on a
german,french,etc.. machine.

Thanks in advance.
Steve.
Feb 3 '06 #1
2 7857
Steve,

No, you can not do it. Microsoft controls don't do it any differently
than you do. They do:

[DefaultValue(typeof(Color), "WindowText")]

Just like you would do.

And no, this would not have a problem in other languages. The color
converter uses the properties as they are exposed off the Color and
SystemColor classes, which are in english.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steve" <st**********@lineone.net> wrote in message
news:us****************@TK2MSFTNGP15.phx.gbl...
Hi, I would like to set the default value of a property on my control by:
[System.ComponentModel.DefaultValue( typeof(Color),
SystemColors.WindowText.ToString() )]

but can't because SystemColors.WindowText is not a constant. Microsoft
controls do it, can I - is there a work round?

I can cheat by...
[System.ComponentModel.DefaultValue(typeof(Color), "Black")]

but its not quite what I want. Plus: if I use the cheat("Black") would
this have any problems with internationalisation - would the control work
on a german,french,etc.. machine.

Thanks in advance.
Steve.

Feb 3 '06 #2
It does.

Thanks.
Steve
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OK**************@TK2MSFTNGP09.phx.gbl...
Steve,

No, you can not do it. Microsoft controls don't do it any differently
than you do. They do:

[DefaultValue(typeof(Color), "WindowText")]

Just like you would do.

And no, this would not have a problem in other languages. The color
converter uses the properties as they are exposed off the Color and
SystemColor classes, which are in english.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steve" <st**********@lineone.net> wrote in message
news:us****************@TK2MSFTNGP15.phx.gbl...
Hi, I would like to set the default value of a property on my control
by:
[System.ComponentModel.DefaultValue( typeof(Color),
SystemColors.WindowText.ToString() )]

but can't because SystemColors.WindowText is not a constant. Microsoft
controls do it, can I - is there a work round?

I can cheat by...
[System.ComponentModel.DefaultValue(typeof(Color), "Black")]

but its not quite what I want. Plus: if I use the cheat("Black") would
this have any problems with internationalisation - would the control work
on a german,french,etc.. machine.

Thanks in advance.
Steve.


Feb 4 '06 #3

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

Similar topics

2
by: timtos | last post by:
I want to set a color property of a user control by default. I am doing it like this: .... DefaultValue(typeof(System.Drawing.Color), "Blue"), .... The compiler likes it but my program...
5
by: bbrik | last post by:
Hi, I'm doing a control that has a custom color property and i want to set a default value. I tried several combinations using the DefaultValue atribute but it didn't work. It must be a...
5
by: schneider | last post by:
Hello, Have an issue with a property using the DefaultValue(True) attribute. Imports System.ComponentModel Public Class Class1 Private m_testValue As Boolean
6
by: Meelis Lilbok | last post by:
Hi Why does property default value not work? When i start my application and dont set value from properties window the value is always "nothing". Whats the point off DefualtValue then? ...
2
by: job | last post by:
I'm having trouble getting the DefaultValue property attribute on my server control show up in design time. Here my property code: <Bindable(True), _ Category("Misc"), _...
10
by: tony | last post by:
Hello!! I have some demo programs written in C# and they have this construction "" see below. I haven't seen this before so what does it mean ? public bool ShowDropDownButtons { get {...
6
by: Peter Hartlén | last post by:
Hi! What's the correct syntax for the default value design time attribute, using classdiagram view and Custom Attributes dialog. For a boolean: DefaultValue(true) DefaultValue("true")...
3
by: Johnny Jörgensen | last post by:
Does anybody know how to correctly specify the defaultvalue attribute for a property whose type is an enum. Example: Public Enum TestValues Value1=1 Value2=2 End Enum
5
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Prior to C# 3.0, I would typically define a property of a custom user control with pattern A: === PATTERN A ========== private bool myBool = true; public bool MyBool { get { return myBool; }...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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...
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...

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.