天天看點

BCB中選擇檔案對話框TOpenDialog過濾字尾名使用方法

BCB中使用TOpenDialog選擇對話框時,直接OpenDialog->Execute()彈出的對話框是顯示所有檔案的,如果我們希望過濾指定的檔案字尾名就需要在Execute()前做一些初始化工作,此處主要使用Filter屬性。代碼如下:[喝小酒的網摘]http://blog.hehehehehe.cn/a/8453.htm

隻顯示txt文本檔案。

OpenDialog1->Filter = "Text files (*.txt)|*.TXT";

多個下拉框,可隻顯示txt檔案,也可隻顯示pas字尾結尾檔案。

OpenDialog1->Filter = "Text files (*.txt)|*.TXT|Pascal files (*.pas)|*.PAS";

下面是一種格式裡面顯示多種字尾名的檔案。

OpenDialog1->Filter = "Pascal files|*.PAS;*.DPK;*.DPR";

顯示全部檔案(All file)時,可用*.*,如下所示:

OpenDialog1->Filter = "All files(*.*)|*.*";

然後直接OpenDialog1->Execute()即可。

還有另外一種用法如下:

SavePictureDialog1->DefaultExt = GraphicExtension(__classid(Graphics::TBitmap));

SavePictureDialog1->Filter = GraphicFilter(__classid(Graphics::TBitmap));

if (SavePictureDialog1->Execute()) 

  // save the graphic [喝小酒的網摘]http://blog.hehehehehe.cn/a/8453.htm

繼續閱讀