我的C#程序中有一个自定义库,它将打开一个自定义文件对话框到自定义位置,我需要做的就是将它调用为一个按钮,但是每次尝试此操作时,它都表示存在问题。Application.Run(new Form1());
说尝试使用不正确的格式。这是我将代码放在按钮而不是openFileDialog
代码区域中的情况吗?每当我尝试调用normal时fileDialog
,它将运行默认的Windows版本。这是我的代码:
public partial class Form1 : Form
{
ALCGalleryLib.ALCGallery theGallery;
ALCGalleryLib.ALCGalleryFile aFile;
string tempFile;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void showOpenDialog_FileOk(object sender, CancelEventArgs e)
{
theGallery = new ALCGalleryLib.ALCGallery(); // this will create a new gallery object and connect to the details it already knows about (it gets them from the registry)
aFile = theGallery.showOpenDialog("All Files,*.*|Excel Workbooks,*.xls?"); // this call will show the gallery dialog and allow you to pick a file. it will get returned in the aFile object (or null if nothing selected)
if (aFile != null)
{
tempFile = aFile.saveToDisk(); // save the aFile object to disk as you will not really be able to do anything with it, and anyway, you probably do not need to do anything else with this object. this will return a temporary filename
// or you can choose where is gets saved with:
// tempFile=aFile.saveToDisk("some filename.xlsx");
// or assign your filename to tempFile and then...
// aFile.saveToDisk(tempFile);
// either of the above calls will save the file from the gallery to disk and return the filename in tempFile
}
else
{
// nothing was selected
}
}
private void openFile_Click(object sender, EventArgs e)
{
theGallery.showOpenDialog("All Files,*.*|Excel Workbooks,*.xls?");
}
}
如果您使用的是Windows 64-bit
操作系统,则这是您的应用程序与ALCGalleryLib之间的冲突,一个是32位的,另一个是64位的。
如果ALCGalleryLib是32位的,请参阅“项目属性”,“构建”选项卡,“平台目标”必须是x86而不是任何CPU或x64。
如果ALCGalleryLib是64位的,请参见“项目属性”,“构建”选项卡,“平台目标”必须是x64或“任何CPU”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句