AK3
Posts: 6
Joined: 2009-07-18
|
Hello,
I?Â?Ð?ém facing a small problem on migrating a Ribbon VBA solution to ADX. My Ribbon contains several toggle buttons which behave like an option group, i.e. only one button can be pressed at the same time. I have used shared callbacks for OnAction and getPressed for that.
VBA code:
Option Explicit
Public gobjRibbon As IRibbonUI
Public gstrBtnName As String
'Callback for customUI.onLoad
Public Sub OnRibbonLoad(objRibbon As IRibbonUI)
Set gobjRibbon = objRibbon
gstrBtnName = "rxtglbtn_01"
End Sub
'Callback for toggle buttons onAction
Sub ToggleButtonShared_Click(control As IRibbonControl, pressed As Boolean)
gstrBtnName = control.ID
gobjRibbon.Invalidate
End Sub
'Callback for toggle buttons getPressed
Sub ToggleButtonShared_GetPressed(control As IRibbonControl, ByRef returnedVal)
returnedVal = (control.ID = gstrBtnName)
End Sub
I tried to migrate the latter one by using ADX PropertyChanging event but I?Â?Ð?ém completely stuck. I would be very glad if someone could provide a solution (preferably in VB). I apologize precautionary if this question has been asked before but I couldn't find it in the forums.
Regards
Armin
|
|
Andrei Smolin
Add-in Express team
Posts: 18830
Joined: 2006-05-11
|
Hello Armin,
A quick way to achieve this is to use this approach:
Private Sub AdxRibbonButton1_OnClick(sender As Object, control As IRibbonControl, pressed As Boolean) Handles AdxRibbonButton1.OnClick, AdxRibbonButton3.OnClick, AdxRibbonButton2.OnClick
Dim buttons() As ADXRibbonButton = New ADXRibbonButton() {Me.AdxRibbonButton1, Me.AdxRibbonButton2, Me.AdxRibbonButton3}
For i As Integer = 0 To 2
If (Not sender Is buttons(i)) Then
buttons(i).Pressed = Not pressed
End If
Next i
End Sub
Note that this approach causes the buttons to be in the same state across all instances of the Ribbon group that contains them (= in all windows of the host application).
If you need these buttons to have different states in different windows of the host application, you need to use the PropertyChanging event to generate a boolean value when Office retrieves the Pressed property of these buttons; IOW, if e.PropertyType = ADXRibbonControlPropertyType.Pressed. In this case you should determine the host's window in which the property is retrieved; e.Context returns a COM object representing the window (e.g. Word.Window). Then you should "calculate" the pressed state of the Ribbon button (sender) in that window and assign the resulting value to e.Value.
Andrei Smolin
Add-in Express Team Leader |
|
AK3
Posts: 6
Joined: 2009-07-18
|
|