locked
How can I access a created Ribbon from other parts of my application? RRS feed

  • السؤال

  • I have created a Ribbon in MS Word with several controls and I want to change the value in a Textbox when I change the active document. To catch the event for document change is no problem with a procedure "Application_DocumentChange()". In this procedure I want to access my Textbox in my Ribbon.

    Where can I find a reference to my Ribbon?

    02/شعبان/1431 07:12 ص

الإجابات

  • Hi Traxx

    Are you using the Ribbon Designer or Ribbon XML?

    The code for your Ribbon is the Ribbon class of your solution, usually named Ribbon1 (.cs or .vb) by default. If you create an object for the control (static internal / shared friend) and instantiate it in the class's constructor, you should be able to access it using Ribbon1.controlObject.PropertyName, assuming you're using the Ribbon Designer. It would be a bit different using RibbonXML and callbacks, but accessing the actual Ribbon class would be the same.


    Cindy Meister, VSTO/Word MVP
    • تم وضع علامة كإجابة بواسطة Traxx_ 03/شعبان/1431 08:34 ص
    02/شعبان/1431 09:38 ص

جميع الردود

  • Hi Traxx

    Are you using the Ribbon Designer or Ribbon XML?

    The code for your Ribbon is the Ribbon class of your solution, usually named Ribbon1 (.cs or .vb) by default. If you create an object for the control (static internal / shared friend) and instantiate it in the class's constructor, you should be able to access it using Ribbon1.controlObject.PropertyName, assuming you're using the Ribbon Designer. It would be a bit different using RibbonXML and callbacks, but accessing the actual Ribbon class would be the same.


    Cindy Meister, VSTO/Word MVP
    • تم وضع علامة كإجابة بواسطة Traxx_ 03/شعبان/1431 08:34 ص
    02/شعبان/1431 09:38 ص
  • Thanks... I thought that I could use some kind of collection such as Application.Ribbons("My Ribbon") or similar... But the provided solution works fine

    /Göran

    03/شعبان/1431 08:33 ص
  • Hi Göran

    Globals.Ribbons(1) will get you the first (or whatever index value you use) Ribbon for the project, but it you'd still need to cast it to the class type in order to access its class members (as opposed to general things belonging to all Ribbon objects).


    Cindy Meister, VSTO/Word MVP
    03/شعبان/1431 08:46 ص
  • If you created your custom Ribbon by using the Ribbon (Visual Designer) item, then you can alternatively access it from other parts of your project by using Globals.Ribbons.YourRibbonClass. When you do this, you will not need to cast this value to the actual class type. For more information, see Accessing the Ribbon at Run Time.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    03/شعبان/1431 04:49 م
    المجيب على الأسئلة
  • Cindy,

    If you have time, I have similar issue posted here.

    Thank you,

    Nam

    17/شعبان/1441 10:51 م