如何限制 OpenFileDialog 只允许用户访问 select 个 PDF 文件?

How can I limit an OpenFileDialog to only allow the user to select PDF files?

ofd.Filter = "pdf files (*.pdf)|*.*";

为什么它仍然可以浏览非pdf文件?这里有什么问题吗?

字符串分为两部分 (FileDialog.Filter docs):

Label|Extension

您的标签是 pdf files (*.pdf),但您过滤的扩展名是 *.*。尝试将其设置为 |*.pdf

总之,您所指定的*.pdf只是描述性文字。它可以是任何东西。 不是用来过滤的