473,561 Members | 3,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Componen tModel.DefaultV alue( typeof(Color),
SystemColors.Wi ndowText.ToStri ng() )]

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

I can cheat by...
[System.Componen tModel.DefaultV alue(typeof(Col or), "Black")]

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

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

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

[DefaultValue(ty peof(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.co m

"Steve" <st**********@l ineone.net> wrote in message
news:us******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi, I would like to set the default value of a property on my control by:
[System.Componen tModel.DefaultV alue( typeof(Color),
SystemColors.Wi ndowText.ToStri ng() )]

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

I can cheat by...
[System.Componen tModel.DefaultV alue(typeof(Col or), "Black")]

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

Thanks in advance.
Steve.

Feb 3 '06 #2
It does.

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

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

[DefaultValue(ty peof(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.co m

"Steve" <st**********@l ineone.net> wrote in message
news:us******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi, I would like to set the default value of a property on my control
by:
[System.Componen tModel.DefaultV alue( typeof(Color),
SystemColors.Wi ndowText.ToStri ng() )]

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

I can cheat by...
[System.Componen tModel.DefaultV alue(typeof(Col or), "Black")]

but its not quite what I want. Plus: if I use the cheat("Black") would
this have any problems with internationalis ation - would the control work
on a german,french,e tc.. 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
11441
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 ignores it! I´ve also tried other things like:
5
12749
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 constant, so i can't do: public Color MyColor { ... } I also tried:
5
1430
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
1906
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? Regards; Meelis
2
1299
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"), _ DefaultValue("myDefaultValue")> _ Public Property MyProperty() As String Get
10
3275
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 { return showDropDownButtons; }
6
9378
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") DefaultValue("bool","true")
3
8433
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
5823
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; } set { myBool = value; } } ======================
0
7637
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...
0
7558
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7851
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. ...
0
8072
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...
1
7605
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...
0
7924
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 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...
0
5177
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3609
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...
1
2055
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 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.