ComponentOne Ribbon for WinForms
C1Ribbon (Classic) Task-Based Help / Embedding Controls in a Ribbon / Embedding a TextBox in a Ribbon Group
In This Topic
    Embedding a TextBox in a Ribbon Group
    In This Topic

    Complete the following steps to add a standard TextBox control to a Ribbon group:

    1. Create a new Ribbon application. For more information see Creating a Ribbon Application Project.
    2. Open the MainRibbonForm to view the Ribbon form, and select View | Code to open Code view.
    3. Add the following code to your project to create a new TextBoxHost class that inherits the RibbonControlHost element:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Public Class TextBoxHost
          Inherits C1.Win.C1Ribbon.RibbonControlHost
          Public Sub New()
              MyBase.New(New System.Windows.Forms.TextBox())
          End Sub
      End Class
      

      To write code in C#

      C#
      Copy Code
      public class TextBoxHost : C1.Win.C1Ribbon.RibbonControlHost
      {
          public TextBoxHost()
              : base(new System.Windows.Forms.TextBox())
          {
          }
      }
      
    4. Build and close your project, and then return to Design view.
    5. Open the main menu floating toolbar, click the Actions button, and select Add Tab.
      add tab A new Ribbon tab with an empty Ribbon group will be added to the Ribbon.
    6. Select the new Ribbon group, and from the floating toolbar click the Action button and select Add ControlHost.
      The Adding RibbonControlHost dialog box will open.
    7. Type the name of the control host in the Adding RibbonControlHost dialog box, for example "ProjectName.FormName+TextBoxHost" replacing ProjectName and FormName with the names of your project and form.
      type in control host
    8. Click OK to close the Adding RibbonControlHost dialog box.
      Notice that the TextBox control now appears in the Ribbon group:
      add ribbon control host

    Tip: When you next add the TextBoxHost element you won't have to type its name. The name of this class will be available in the drop-down list in the Adding RibbonControlHost dialog box.


    This topic illustrates the following:

    At run time, you will be able to interact with the TextBoxHost element as you would a standard TextBox.
    textbox host element

    The RibbonControlHost class publishes the standard properties and events of the hosted control. To access other properties, methods, and events of the hosted control use the RibbonControlHost.Control property.

    It is also possible to override methods with events, such as OnSubscribeControlEvents, to handle events raised by the hosted control. You can add custom functionality into properties to enhance the hosted control.