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.