C#Windows窗体 - 如何以编程方式设置文件夹的图像预览(VSTO 2010) [英] C# Windows Forms - How to programmatically set image preview for file folder (VSTO 2010)

查看:209
本文介绍了C#Windows窗体 - 如何以编程方式设置文件夹的图像预览(VSTO 2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows窗体 - VSTO - Outlook

Windows Forms - VSTO - Outlook

背景 - 我正在创建用于Office的数字存档加载项,用户可以在该数据库中搜索客户端(文档所属的客户端),并根据文件的性质将文件保存到相应的文件夹中。到目前为止,这是按照计划为Word工作,但我现在正在使用更多需要考虑的Outlook(附件,邮件正文等)。

Background - I am creating a digital archive add-in for Office where the user can search the database for the client (whom the document belongs to) and it will save the file to the appropriate folder(s) based on the nature of the file. So far this is working for Word as planned but I am now using Outlook which has more to consider (attachments, message body, etc.).

我已经让它工作了到目前为止,附件被保存到一个临时文件夹(每次窗体关闭时清空)准备好进行排序,我可以获得有关发件人/主题/电子邮件正文的信息。附件列表设置为CheckedListBox

I have got it working so far that the attachments are saved into a temporary folder (which is emptied each time the windows form closes) ready to be sorted and I can obtain information about sender/subject/email body. The list of attachments is set out into a CheckedListBox

当前问题 - 当用户希望存档附件时(很多文档/扫描的文件会出现),图像会混淆,因为它们可能是必要的或完全不重要,所以我希望预览图像。

Current Problem - When a user is looking to archive an attachment (a lot of documents/scanned documents will come up), images will be confusing as they may be necessary or entirely unimportant so I wish to preview the images.

我试图在

private void chkAttachments_SelectedValueChanged(object sender, EventArgs e)

图片显示在 picAttachPreview (PictureBox)作为该文件的预览。这将从 tempfolder @c:\ temp \ DigitalArchive)中获取图像。

The image shows in picAttachPreview (PictureBox) as a preview of that file. This will be taking the image from tempfolder (@"c:\temp\DigitalArchive").

我明白这是错误的,但我试图设置屏幕上显示的SelectedValueChanged事件的图像来源。

I understand this is wrong but I am trying to set the source for the image shown on screen on that SelectedValueChanged event.

我的[错误]代码 -

if(chkAttachments.Text.Contains(".jpg"))
        {
            var selectedImage = chkAttachments.SelectedValue.ToString();
            picAttachPreview.Image = tempfolder + @"\" + selectedImage; //(A)
        }

(A)行是问题,虽然我理解为什么,但我不知道如何解决它。文件路径由 tempfolder selectedImage (例如ScannedDoc.jpg)构成,但文件路径类型为String但 picAttachPreview 是System.Drawing.Image所以我假设我正在查看 picAttachPreview 的错误属性来设置图像的来源。

The (A) line is the issue and although I understand why, I don't know how to resolve it. The filepath is constructed with tempfolder and selectedImage (e.g. ScannedDoc.jpg) but the file path type is String but picAttachPreview is System.Drawing.Image so I assume I am looking at the wrong property of picAttachPreview to set the source of the image.

任何帮助或指导都将非常感激。谢谢。

Any help or guidance will be immensely appreciated. Thank you.

(如果您知道任何好方法我可以设置相同的文档/ PDF预览性质,那么我将非常感激)

(Also if you know of any good way I can set the same nature of preview for documents/PDF then I will be immensely grateful)

编辑虽然该链接解决了我的部分问题,但 chkAttachments.SelectedValue.ToString()我在下面回答。 (如果有人可以就这种情况告诉我网站礼节。我是否删除了问题或者留下了我找到的答案,以便人们可以在以后找到解决同一问题的方法?谢谢你)

Edit Although the link solves part of my problem, there is an issue with chkAttachments.SelectedValue.ToString() which I answered below. (If anyone can advise me on the site etiquette for this situation. Do I delete the question or leave it with the answer I found so that people can find the solution to the same problem in future? Thank you)

推荐答案

经过一番游戏后,我发现另一个问题( chkAttachment.Text 有效,而 .SelectedValue.ToString()没有。

After some playing around, I found another problem (chkAttachment.Text works whereas .SelectedValue.ToString() does not.

此外,字符串到图像格式的问题通过在前面加上路径来解决 Image.FromFile(

Also the issue with the string to image format is resolved by prefixing the path with Image.FromFile(

因此,选择时更改图像的正确方法是:

So the correct way of changing the image upon selection is:

if(chkAttachments.Text.Contains(".jpg"))
        {
            var selectedImage = chkAttachments.Text;
            picAttachPreview.Image = Image.FromFile(tempfolder + @"\" + selectedImage);
        }

这篇关于C#Windows窗体 - 如何以编程方式设置文件夹的图像预览(VSTO 2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆