Ich habe eine benutzerdefinierte Bibliothek in meinem C# -Programm, die einen benutzerdefinierten Dateidialog zu einem benutzerdefinierten Speicherort öffnen, und alles, was ich tun muss, ist es auf eine Schaltfläche, aber jedes Mal aufzurufen Ich versuche das, es sagt, dass es ein Problem mit der Application.Run(new Form1());
gibt, dass ein Versuch mit einem falschen Format gemacht wurde. Ist das ein Fall von mir, den Code in den Knopf anstatt den openFileDialog
Codebereich zu setzen? Immer wenn ich versuche, einen normalen fileDialog
anzurufen, wird die Windows-Standardversion ausgeführt. Hier ist mein Code:Aufruf einer benutzerdefinierten Bibliotheksfunktion zu einer Schaltfläche mit C#
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?");
}
}
Scheint wie ein 32-/64-Bit-Problem. Siehe diese Frage: http://stackoverflow.com/questions/2023766/an-versuchs-was-made-to-load-a-program-with-an-incorrect-format-even-when-the-p – HHLV