2

我有一个带有编辑框的简单 Outlook 功能区。用户单击发送按钮后,我会在编辑框中捕获字符串并在 Application_ItemSend 中使用它。

我的问题是,功能完成后,我想重置功能区的 UI(只是编辑框),以便用户在打开新消息屏幕时不会在同一个框中输入先前键入的字符串。我尝试了 Ribbon.Invalidate 但我似乎无法摆脱那个字符串值。当我重新打开“新电子邮件”屏幕时,旧值仍然存在。

这是代码:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load_2010">
<ribbon>
<tabs>
  <tab idMso="TabNewMailMessage">
    <group id="TaskManager" insertBeforeMso="GroupSend" label="Task Manager">
      <editBox id="editboxTaskID" label="Task ID #: " onChange="editboxTaskID_OnChange" 
imageMso="RecordsAddFromOutlook" sizeString="wwwwww"/>
    </group>
  </tab>
</tabs>
</ribbon>
</customUI>

和VB代码:

<Runtime.InteropServices.ComVisible(True)> _
Public Class CustomRibbon
Implements Office.IRibbonExtensibility

Private ribbon As Office.IRibbonUI
Public strTask_ID As String = ""

Public Sub New()

End Sub

Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Office.IRibbonExtensibility.GetCustomUI
    Return GetResourceText("Addin.Ribbon.xml")
End Function

Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean)
    Me.ribbon.Invalidate()
    Try

 'SOME CODE HERE WHICH WORKS FINE!

    Catch ex As Exception
    End Try

End Sub


'Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1.
Public Sub Ribbon_Load_2010(ByVal ribbonUI As Office.IRibbonUI)
    Me.ribbon = ribbonUI
    AddHandler Globals.ThisAddIn.Application.ItemSend, AddressOf Application_ItemSend
End Sub

Public Sub editboxTaskID_OnChange(ByVal control As Office.IRibbonControl, ByVal Text As String)
    strTask_ID = Text
End Sub

Public Sub AttachmentRibonClick(ByVal control As Microsoft.Office.Core.IRibbonControl)
    Globals.ThisAddIn.TriggerTaskWindow("Attachment")
End Sub

Private Shared Function GetResourceText(ByVal resourceName As String) As String
    Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
    Dim resourceNames() As String = asm.GetManifestResourceNames()
    For i As Integer = 0 To resourceNames.Length - 1
        If String.Compare(resourceName, resourceNames(i), StringComparison.OrdinalIgnoreCase) = 0 Then
            Using resourceReader As IO.StreamReader = New IO.StreamReader(asm.GetManifestResourceStream(resourceNames(i)))
                If resourceReader IsNot Nothing Then
                    Return resourceReader.ReadToEnd()
                End If
            End Using
        End If
    Next
    Return Nothing
End Function
End Class
4

2 回答 2

6

invalidate 方法用于表示控件已更新并且需要在屏幕上重新呈现。它不会清除控件中的数据。您需要做的是将有问题的字符串值存储为空字符串的控件(在本例中为编辑框)上设置属性。

于 2012-11-07T15:43:42.093 回答
4

好的,我想通了。

显然,在您使控件无效后,您需要使用 Editbox 的 GetText 函数来初始化值。

    Public Function editboxTaskID_GetText(ByVal control As Office.IRibbonControl) As String
        Return ""
    End Function

我还注意到其他网站对该功能使用不同的签名 - 这不起作用。我相信微软在迁移到 2010 Interop 时将其从 Sub 更改为 Function。

我希望微软对此有更好的文档。

快乐编程!

于 2012-11-15T14:10:39.037 回答