[Solved] Dynamically set focus to another program in C#


You can add reference to Microsoft.VisualBasic and try AppActivate

Microsoft.VisualBasic.Interaction.AppActivate("Visual"); 

Update

AppActivate finds only main windows whose title starts with the title parameter (the title parameter needs at least 3 characters), but the Visual Studio main window title is usually something like Solution Name - Microsoft Visual Studio, so you can either use the solution name or :

var processes = Process.GetProcessesByName("devenv");
if(processes.Any()) 
    Microsoft.VisualBasic.Interaction.AppActivate(processes[0].MainWindowTitle); 

1

solved Dynamically set focus to another program in C#