-2

当我使用 openfiledialog.Filter 时出现问题。这是我的代码:

openFileDialog1.Filter = "Video and Music Files (*.asf, *.wma, *.wmv, *.wm, *.asx, *.wax, *.wvx, *.wmx, *.wpl, *.dvr-ms, *.wmd, *.avi, *.mpg, *.mpeg, *.m1v, *.mp2, *.mp3, *.mpa, *.mpe, *.m3u, *.mid, *.midi, *.rmi. *.aif, *.aifc, *.aiff, *.au, *.snd, *.wav, *.cda, *.ivf, *.wmz, *.wms, *.mov, *.m4a, *.mp4, *.m4v, *.mp4v, *.3g2, *.3gp2, *.3gp, *.3gpp, *.aac, *.adt, *.adts, *.m2ts)|*.asf *.wma *.wmv *.wm *.asx *.wax *.wvx *.wmx *.wpl *.dvr-ms *.wmd *.avi *.mpg *.mpeg *.m1v *.mp2 *.mp3 *.mpa *.mpe *.m3u *.mid *.midi *.rmi *.aif *.aifc *.aiff *.au *.snd *.wav *.cda *.ivf *.wmz *.wms *.mov *.m4a *.mp4 *.m4v *.mp4v *.3g2 *.3gp2 *.3gp *.3gpp *.aac *.adt *.adts *.m2ts|All Files (*.*)|*.*"
4

2 回答 2

4

Idle_Mind 就在下面,您缺少分号:

openFileDialog1.Filter = "Video and Music Files (*.asf, *.wma, *.wmv, *.wm, *.asx, *.wax, *.wvx, *.wmx, *.wpl, *.dvr-ms, *.wmd, *.avi, *.mpg, *.mpeg, *.m1v, *.mp2, *.mp3, *.mpa, *.mpe, *.m3u, *.mid, *.midi, *.rmi. *.aif, *.aifc, *.aiff, *.au, *.snd, *.wav, *.cda, *.ivf, *.wmz, *.wms, *.mov, *.m4a, *.mp4, *.m4v, *.mp4v, *.3g2, *.3gp2, *.3gp, *.3gpp, *.aac, *.adt, *.adts, *.m2ts)|*.asf; *.wma; *.wmv; *.wm; *.asx; *.wax; *.wvx; *.wmx; *.wpl; *.dvr-ms; *.wmd; *.avi; *.mpg; *.mpeg; *.m1v; *.mp2; *.mp3; *.mpa; *.mpe; *.m3u; *.mid; *.midi; *.rmi. *.aif; *.aifc; *.aiff; *.au; *.snd; *.wav; *.cda; *.ivf; *.wmz; *.wms; *.mov; *.m4a; *.mp4; *.m4v; *.mp4v; *.3g2; *.3gp2; *.3gp; *.3gpp; *.aac; *.adt; *.adts; *.m2ts|All Files (*.*)|*.*"    

OpenDialog.Filter 属性有点讨厌。它在交替的值对之间使用管道分隔符,如下所示:

openFileDialog1.Filter = "option 1|rules for option 1|option 2|rules for option 2|..."    

http://msdn.microsoft.com/en-us/library/system.windows.controls.openfiledialog.filter(v=vs.95).aspx

于 2013-11-10T22:07:13.797 回答
1

您需要用分号分隔实际的过滤器,例如:

*.abc;*.xyz;*.txt

条目是成对的。第一部分是描述,可以随意格式化。第二部分是用分号分隔的过滤器列表。第一部分和第二部分由管道符号 | 分隔。

每组对也由管道符号分隔。

文档中的示例非常好:

Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*

具体来说,您的过滤器应如下所示:

OpenFileDialog1.Filter = "Video and Music Files (*.asf, *.wma, *.wmv, *.wm, *.asx, *.wax, *.wvx, *.wmx, *.wpl, *.dvr-ms, *.wmd, *.avi, *.mpg, *.mpeg, *.m1v, *.mp2, *.mp3, *.mpa, *.mpe, *.m3u, *.mid, *.midi, *.rmi. *.aif, *.aifc, *.aiff, *.au, *.snd, *.wav, *.cda, *.ivf, *.wmz, *.wms, *.mov, *.m4a, *.mp4, *.m4v, *.mp4v, *.3g2, *.3gp2, *.3gp, *.3gpp, *.aac, *.adt, *.adts, *.m2ts)|*.asf;*.wma;*.wmv;*.wm;*.asx;*.wax;*.wvx;*.wmx;*.wpl;*.dvr-ms;*.wmd;*.avi;*.mpg;*.mpeg;*.m1v;*.mp2;*.mp3;*.mpa;*.mpe;*.m3u;*.mid;*.midi;*.rmi;*.aif;*.aifc;*.aiff;*.au;*.snd;*.wav;*.cda;*.ivf;*.wmz;*.wms;*.mov;*.m4a;*.mp4;*.m4v;*.mp4v;*.3g2;*.3gp2;*.3gp;*.3gpp;*.aac;*.adt;*.adts;*.m2ts|All Files (*.*)|*.*"
于 2013-11-11T01:43:41.227 回答