The actions that users need to use regularly should always be available on the Ribbon control, where the user can access them within a few clicks. However, certain actions are exclusive to a certain element; for example, an action that allows you to format the font of text may only be necessary when users are editing text in a RichTextBox. In the aforementioned case, it would be beneficial to place this action (and all other actions specific to RichTextBoxes) under a contextual tabs that only appears when users have selected the RichTextBox. This topic demonstrates how to add a contextual tab group that appears only when a RichTextBox is selected.
Complete the following steps:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub richTextBox1_Enter(sender As Object, e As EventArgs) ribbonContextualTabGroup1.Visible = True End Sub Private Sub richTextBox1_Leave(sender As Object, e As EventArgs) ribbonContextualTabGroup1.Visible = False End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void richTextBox1_Enter(object sender, EventArgs e) { ribbonContextualTabGroup1.Visible = true; } private void richTextBox1_Leave(object sender, EventArgs e) { ribbonContextualTabGroup1.Visible = false; } |
And that’s it! Ribbon for WinForms makes it that simple to add a contextual tab to the Ribbon interface.