You can add a C1ContextMenu to a control at design time or through code. Click on either of the following links to expand the steps for the designer or for the code.
To add a C1ContextMenu to a Control at design time
To create a context menu and associate it with a menu item, complete the following tasks:
To add a C1ContextMenu to a control programmatically
To add a C1ContextMenu to a control, complete the following steps:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim ch As C1.Win.C1Command.C1CommandHolder ch = C1CommandHolder.CreateCommandHolder(Me) |
To write code in C#
C# |
Copy Code
|
---|---|
C1CommandHolder ch = C1CommandHolder.CreateCommandHolder(this); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
'Create and set up the Copy command Dim cmdCopy As C1Command = ch.CreateCommand() cmdCopy.Text = "&Copy" AddHandler cmdCopy.Click, AddressOf clickCopy AddHandler cmdCopy.CommandStateQuery, AddressOf queryCopy |
To write code in C#
C# |
Copy Code
|
---|---|
// Create and set up the Copy command C1Command cmdCopy = ch.CreateCommand(); cmdCopy.Text = "&Copy"; cmdCopy.Click += new C1.Win.C1Command.ClickEventHandler(clickCopy); cmdCopy.CommandStateQuery += new C1.Win.C1Command.CommandStateQueryEventHandler(queryCopy); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim cm As C1ContextMenu = Ctype(ch.CreateCommand(GetType(C1ContextMenu)), C1ContextMenu) 'Fill it with the links to the commands cm.CommandLinks.Add(New C1CommandLink (cmdCopy)) ch.SetC1ContextMenu(TextBox1, cm) |
To write code in C#
C# |
Copy Code
|
---|---|
C1ContextMenu cm = ch.CreateCommand(typeof(C1ContextMenu)) as C1ContextMenu; // Fill it with the links to the commands cm.CommandLinks.Add(new C1CommandLink(cmdCopy)); ch.SetC1ContextMenu(textBox1, cm); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub clickCopy(ByVal sender As Object, ByVal e As C1.Win.C1Command.ClickEventArgs) Me.textBox1.Copy() End Sub 'provides the current state of the copy command Private Sub queryCopy(ByVal sender As Object, ByVal e As C1.Win.C1Command.CommandStateQueryEventArgs) e.Enabled = Me.textBox1.SelectionLength > 0 End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void clickCopy(object sender, C1.Win.C1Command.ClickEventArgs e) { this.textBox1.Copy(); } //provides the current state of the copy command private void queryCopy(object sender, C1.Win.C1Command.CommandStateQueryEventArgs e) { e.Enabled = this.textBox1.SelectionLength > 0; } |