Open or Form1 or form2 on winform program startup

Asked

Viewed 967 times

0

I have a program in vb6 and has two buttons - A scanner and another for scanning images. I created a program in c# winform where the project has 2 Forms - a Form1 for the scanner and another form2 for the scanned image queries. The two on . Net work perfectly. I wonder if there is how to do that when running the program . net , through a 1 or 2 parameter, choose which of the Forms will run through VB6

In Vb I intend depending on the button clicked, will record in a table or 1 or 2 . On the button chosen, will call the application through the shell. Starting the application, I will consult the table with the chosen parameter and open the requested form.

I just don’t know how to do it on . net c#. The start of Program.Cs is like this on . net

[STAThread]
static void Main()
{
    ConsultaImagens2 f2 = new ConsultaImagens2();
    Application.Run(f2);
    MainFrame f1 = new MainFrame();
    f1.Close();

    MainFrame mf = new MainFrame();
    ConsultaImagens mf = new ConsultaImagens();
    Application.Run(mf);
    MainFrame mf1 = new MainFrame();
    mf1.Close();
}
  • You want the user to choose which application (Form1 or form2) to run, when opening the program? you can create a new one form with options and a button that will check these options and open the respective program,

1 answer

2


Yes, this is completely possible. For this you can use the parameters in the method Main. How will you call the executable by the prompt, just do

C: Algumapasta > nomenAplicacao.exe Consultaimagens2

The code goes something like this:

Note: I did not understand why instantiating that MainFrame then I removed it.

[STAThread]
static void Main(string[] args)
{
    Form formAbrir;

    if(args[1] == "ConsultaImagens2") //a posição 0 é sempre o caminho do arquivo
        formAbrir = new ConsultaImgens2();
    else
        formAbrir = new ConsultaImagens();

    Application.Run(formAbrir);
}
  • For one of the buttons I am putting the following routine in shell, and when rotating it only opens the form Query images : As follows "Shellexecute Me.hwnd, "open", "C:/Scannersefaz_v08/Scan.exe " & Query Imagens2 & " ", "C:/", "C:/", vbNormalFocus" I passed parameters for args and this opening correctly in c#

  • So there’s something wrong with crossing parameters

  • Is this syntax correct or should I change it? Shellexecute Me.hwnd, "open", "C:/Scannersefaz_v08/Scan.exe " & Query 2 & " ", "C:/", "C:/", vbNormalFocus" ?

  • Perfect Jbueno, it worked. I was just giving blank space in the shelll. Already corrected Shellexecute Me.hwnd, "open", "C:/Scannersefaz_v08/Query/Query esc", "C:/", "C:/", vbNormalFocus

Browser other questions tagged

You are not signed in. Login or sign up in order to post.