maui- can run exe of framework 4.7.2(winform)

Dani_S 4,461 Reputation points
2023-08-22T11:47:10.6133333+00:00

Hi,

Can Maui app can run exe of framework 4.7.2 (WinForms) , using process info ?

Thanks in advance,

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,079 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,106 Reputation points Microsoft External Staff
    2023-08-23T03:07:46.98+00:00

    Hello,

    After testing, you could follow the steps below to open the Winforms program in MAUI.

    For WinForms application, this example implements a WinForms program that accepts parameters and displays them in a label.

    Step 1. Add parameters to the Forms main function:

    static void Main(string[] args)
    {
        // To customize application configuration such as set high DPI settings or default font,
        // see https://aka.ms/applicationconfiguration.
        string str = "";
        if (args.Length != 0)
        {
            foreach (string arg in args)
            {
                str += arg;
            }
        }
        ApplicationConfiguration.Initialize();
        Application.Run(new Form1(str));
    }
    

    Step 2. Implement a constructor for the Forms form that receives parameters.

    public Form1(string str)
    {
        InitializeComponent();
        label1.Text = str;
    }
    

    Step 3. Release the WinForms application.

    For MAUI application:

    Step 4. Pass the parameters via ProcessInfo and launch this WinForms application.

    private void CounterBtn_Clicked(object sender, EventArgs e)
    {
        var path = "C:\\wpf1_test\\WinFormsApp3.exe"; //WinForms program path
        if (File.Exists(path))
        {
            ProcessStartInfo startInfo = new ProcessStartInfo(path, "hello world")
            {
                CreateNoWindow = true,
                UseShellExecute = true,
            };
            Process.Start(startInfo);
        }
    }
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.