Salut a tous, je suis nouveau au C# avec un background de C et python.
J'essaye de faire un petit "wrapper" pour un programme progai.exe qui fonctionne en ligne de commande, comme
J'utilise donc System.Windows.Forms.OpenFileDialog pour avoir un super selecteur de fichier et puis le lance le programme avec Process.start()
Code : Sélectionner tout - Visualiser dans une fenêtre à part prograi.exe -f fichier.ai1
Deux problemes:
1) Le filtre n'a pas l'air de fonctionner correctement, ou plutot, il fonctionne au debut mais si je change de type de fichier, passant de ai1 and ai2 (voir code), plus rien n'est affiche. Pareil si je selectionne *.*
C'est comme si il manquait un rafraichissement une fois le changement fait...
2) Si je change d'avis et clique sur "cancel", je recois une error du Just-Time-Debugger, assez enervant. Comment sans debarrasser pour que je puisse mettre mon propre message a la place?
Merci d'avance
David
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 using System; using System.IO; using System.Text; using System.Windows.Forms; using System.Diagnostics; public class cMain{ static void Main(){ string InitDir = "."; string SelecFile; string Arguments; /*Gets file name from an OpenFile dialog*/ SelecFile = SelectTextFile(InitDir); /*Creates the appropriate argument string*/ Arguments = String.Format("-f {0}",SelecFile); /*Starts up the program*/ Process p= new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle = 0; p.StartInfo.WorkingDirectory = "."; p.StartInfo.FileName = "progai.exe"; p.StartInfo.Arguments = Arguments; p.Start(); p.WaitForExit(); } static public string SelectTextFile ( string initialDirectory ) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "ai1 files|*.ai1|ai2 files|*.ai2|All files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.InitialDirectory = initialDirectory; dialog.Title = "Select a data file"; return ( dialog.ShowDialog() == DialogResult.OK ) ? dialog.FileName : null; } }
Partager