Click here to Skip to main content
15,910,981 members
Home / Discussions / C#
   

C#

 
QuestionDefaultValueAtribute Pin
alexeychik200115-Mar-07 8:39
alexeychik200115-Mar-07 8:39 
AnswerRe: DefaultValueAtribute Pin
mav.northwind15-Mar-07 9:28
mav.northwind15-Mar-07 9:28 
GeneralRe: DefaultValueAtribute Pin
alexeychik200115-Mar-07 9:47
alexeychik200115-Mar-07 9:47 
GeneralRe: DefaultValueAtribute Pin
mav.northwind15-Mar-07 9:54
mav.northwind15-Mar-07 9:54 
GeneralRe: DefaultValueAtribute Pin
alexeychik200115-Mar-07 10:03
alexeychik200115-Mar-07 10:03 
GeneralRe: DefaultValueAtribute Pin
Sean Michael Murphy15-Mar-07 10:31
Sean Michael Murphy15-Mar-07 10:31 
GeneralRe: DefaultValueAtribute Pin
alexeychik200115-Mar-07 10:46
alexeychik200115-Mar-07 10:46 
GeneralRe: DefaultValueAtribute Pin
Sean Michael Murphy15-Mar-07 11:22
Sean Michael Murphy15-Mar-07 11:22 
alexeychik2001 wrote:
Take any control, for instance Timer and its property Interval. If you take a look on its metadata you'll see
[DefaultValue(100)]
public int Interval { get; set; }

I don't want a varable defaul value. I want that this default value could be seen at design time and changed at property window. How to do it?


You can't. The default value is, as you see, compiled in the code. There is only 1 default value that a Timer.Interval property can have, and it's set at compile time.

You can't change that at design time, and you can't change it at run-time.

You can create a new control inherited from Timer that has a different default value for Interval (I just tried it), but all instances of that control will only have the single default value.

C#
namespace WindowsApplication1{
   class MyTimer : System.Windows.Forms.Timer {
      public MyTimer() {
         base.Interval = 200;
      }
   
      [System.ComponentModel.DefaultValue(200)]
      public new int Interval {
         get { return base.Interval; }
         set { base.Interval = value; }
      }
   }
}

All instances of this new control have a default value of 200 for Interval, but it requires the code in the constructor, and it's constant for all uses (design time or run-time).

Share and enjoy.
Sean
Questionfilesystem listview Pin
alpdoruk15-Mar-07 8:24
alpdoruk15-Mar-07 8:24 
AnswerRe: filesystem listview Pin
Ed.Poore19-Mar-07 13:10
Ed.Poore19-Mar-07 13:10 
QuestionComboBox & DataBindings Problem Pin
Urfinek15-Mar-07 8:15
Urfinek15-Mar-07 8:15 
AnswerRe: ComboBox & DataBindings Problem Pin
yarns15-Mar-07 19:04
yarns15-Mar-07 19:04 
Questionmy problem Pin
groundzero11115-Mar-07 7:53
groundzero11115-Mar-07 7:53 
AnswerRe: my problem Pin
Dave Kreskowiak15-Mar-07 13:19
mveDave Kreskowiak15-Mar-07 13:19 
QuestionContext menu glitch Pin
Anthony Mushrow15-Mar-07 7:29
professionalAnthony Mushrow15-Mar-07 7:29 
QuestionDataGridView Pin
aranhamarvel15-Mar-07 7:27
aranhamarvel15-Mar-07 7:27 
Questioninsert icon in the taskbar at runtime Pin
iman_kh15-Mar-07 7:24
iman_kh15-Mar-07 7:24 
AnswerRe: insert icon in the taskbar at runtime Pin
Stefan Troschuetz15-Mar-07 9:03
Stefan Troschuetz15-Mar-07 9:03 
QuestionAccept changes in db Pin
iman_kh15-Mar-07 7:17
iman_kh15-Mar-07 7:17 
QuestionPictureBox VS ? Pin
aei_totten15-Mar-07 7:02
aei_totten15-Mar-07 7:02 
AnswerRe: PictureBox VS ? Pin
aei_totten15-Mar-07 10:43
aei_totten15-Mar-07 10:43 
QuestionC# Container like the VB Collection??? Pin
code-frog15-Mar-07 6:34
professionalcode-frog15-Mar-07 6:34 
AnswerRe: C# Container like the VB Collection??? Pin
Colin Angus Mackay15-Mar-07 6:44
Colin Angus Mackay15-Mar-07 6:44 
GeneralRe: C# Container like the VB Collection??? Pin
code-frog15-Mar-07 11:11
professionalcode-frog15-Mar-07 11:11 
AnswerRe: C# Container like the VB Collection??? Pin
mav.northwind15-Mar-07 9:33
mav.northwind15-Mar-07 9:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.