使用 C# 将自定义库函数调用到按钮

Calling a custom library function to a button using C#

我的 C# 程序中有一个自定义库,它将在自定义位置打开一个自定义文件对话框,我需要做的就是调用一个按钮,但每次我尝试这个时,它都说那里Application.Run(new Form1()); 表示尝试使用不正确的格式是一个问题。这是我将代码放在按钮而不是 openFileDialog 代码区域的情况吗?每当我尝试调用普通 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。