1 /***************************************************************************
3 Copyright (c) Microsoft Corporation. All rights reserved.
4 THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
5 ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
6 IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
7 PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9 ***************************************************************************/
11 using Microsoft
.VisualStudio
.Shell
;
13 using System
.ComponentModel
.Design
;
14 using System
.Globalization
;
16 namespace Microsoft
.Samples
.VisualStudio
.MenuCommands
19 /// This class implements a very specific type of command: this command will count the
20 /// number of times the user has clicked on it and will change its text to show this count.
22 internal class DynamicTextCommand
: OleMenuCommand
24 // Counter of the clicks.
25 private int clickCount
;
28 /// This is the function that is called when the user clicks on the menu command.
29 /// It will check that the selected object is actually an instance of this class and
30 /// increment its click counter.
32 private static void ClickCallback(object sender
, EventArgs args
)
34 DynamicTextCommand cmd
= sender
as DynamicTextCommand
;
42 /// Creates a new DynamicTextCommand object with a specific CommandID and base text.
44 public DynamicTextCommand(CommandID id
, string text
) :
45 base(new EventHandler(ClickCallback
), id
, text
)
50 /// If a command is defined with the TEXTCHANGES flag in the VSCT file and this package is
51 /// loaded, then Visual Studio will call this property to get the text to display.
53 public override string Text
57 return string.Format(CultureInfo
.CurrentCulture
, VSPackage
.ResourceManager
.GetString("DynamicTextFormat"), base.Text
, clickCount
);
59 set { base.Text = value; }