gpt4 book ai didi

vb.net - Interop.Outlook 在拖放时不会清除选定的邮件

转载 作者:行者123 更新时间:2023-12-02 07:10:35 26 4
gpt4 key购买 nike

我有一个可以放置邮件项目的控件,工作正常,但我无法用它来清除选择/项目。

例如:我拖放邮件 1 --> 邮件 1 在我的列表中我从列表中删除邮件 1 返回 Outlook 并拖放邮件 2
邮件 2 出现在我的列表中,但邮件 1 也恢复了!我发现了很多关于 Marshal.ReleaseComObject 的帖子,但我想我没有以正确的方式这样做?

规范:VS2010,4.0框架。 Windows 7 操作系统、Outlook 2010

这是我的代码的一部分:

调用我的Save方法:

ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then
Try
Dim SafeSaveMethod As New dlgCallSaveMails(AddressOf SaveMailsFromSelection)
Me.BeginInvoke(SafeSaveMethod, Me.FileData.Pad)

保存方法:

Private Sub SaveMailsFromSelection(_path As String)
' File uit Outlook
Dim x As Integer
Dim xitmndx As Integer = 0
Dim DestFile As String
Dim oOutLook As New Outlook.Application
Dim oExplorer As Outlook.Explorer
Dim oSelection As Outlook.Selection
Dim strFile As String

oExplorer = oOutLook.ActiveExplorer
oSelection = oExplorer.Selection
Dim currentFolder As MAPIFolder = oExplorer.CurrentFolder
Dim folders As Folders = currentFolder.Folders


Try
For Each mitem As Object In oSelection
xitmndx += 1

Dim mi As Microsoft.Office.Interop.Outlook.MailItem = TryCast(mitem, Microsoft.Office.Interop.Outlook.MailItem)

mi.SaveAs(_path & "\" & String.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", mi.CreationTime) & "-" & CleanInput(mi.Subject) & ".msg", Outlook.OlSaveAsType.olMSG)

Marshal.ReleaseComObject(mi)
mi = Nothing
Next

Catch ex As System.Exception
WriteError2EventLog("Error picDropZone_DragDrop 4: " & ex.ToString)
MsgBox(Err.Description, MsgBoxStyle.Exclamation, "mycontrol")
Finally
Marshal.ReleaseComObject(oExplorer)
Marshal.ReleaseComObject(oSelection)
Marshal.ReleaseComObject(currentFolder)
Marshal.ReleaseComObject(folders)
Marshal.FinalReleaseComObject(oExplorer)
End Try
End Sub

我也尝试了oExplorer.ClearSelection(),但从 count 属性可以看出,它根本不清除

最佳答案

在花了几个小时阅读此问题的不同解决方案后,当移动到另一个程序中可以处理拖放的控件时,这最终成为 Outlook 处理输入事件的方式中的一个错误,我发现您可以用一行代码修复它,这是应该传播的东西!

Microsoft 使用剪贴板来存储有关选择的信息等。 Outlook 为此目的使用的类隐藏在名为 RenPrivateMessages 的键后面。它无法使用,因为他们不会释放接口(interface),但通过阅读它,您可以清除对选择的锁定。

因此,您在代码中的 drop 事件中所需要做的就是添加此行(假定您的 EventArg 名为 e):

e.data.GetData("RenPrivateMessages");

关于vb.net - Interop.Outlook 在拖放时不会清除选定的邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14090420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com