The following code demonstrates how to create and customize command contexts:
C# |
Copy Code
|
//create a command context
NCommandContext context = new NCommandContext();
//customize context's visual properties
context.Properties.Text = "MyCommandContext";
context.Properties.Style = CommandStyle.ImageAndText;
//specify imagelist and image index
context.Properties.ImageList = myImageList;
context.Properties.ImageIndex = 0;
|
Visual Basic |
Copy Code
|
'create a command context
Dim context As NCommandContext = New NCommandContext()
'customize context's visual properties
context.Properties.Text = "MyCommandContext"
context.Properties.Style = CommandStyle.ImageAndText
'specify imagelist and image index
context.Properties.ImageList = myImageList
context.Properties.ImageIndex = 0
|
You can create a command from a context using the following code:
C# |
Copy Code
|
//assume that we have a valid context created
NCommand command = NCommand.FromContext(myCommandContext);
|
Visual Basic |
Copy Code
|
'assume that we have a valid context created
Dim command As NCommand = NCommand.FromContext(myCommandContext)
|
The FromContext method will initialize a new command (command type depends on the context's type), update its properties and associate it with the context.
You can group contexts in ranges using the RangeID property, which should point to a valid ID of a NRange object. This feature is primarily used by the NCommandBarsManager component.
The following example demonstrates how to create a range and two command contexts which RangeID property points to that range:
C# |
Copy Code
|
//create the range
NRange range = new NRange();
range.ID = 1;
range.Name = "Standard";
//create two command contexts
NCommandContext context;
context = new NCommandContext();
context.RangeID = 1;
context = new NCommandContext();
context.RangeID = 1;
|
Visual Basic |
Copy Code
|
'create the range
Dim range As NRange = New NRange()
range.ID = 1
range.Name = "Standard"
'create two command contexts
Dim context As NCommandContext
context = New NCommandContext()
context.RangeID = 1
context = New NCommandContext()
context.RangeID = 1
|
The NCommandBarsManager component exposes Contexts and Ranges properties which help manager to organize contexts by ranges.
For more information about building docking command bars framework see Docking Toolbars Framework tutorial.