Selected Window? If by selected you mean active form then try this:-
foreach(Form frm in Application.OpenForms)
{
if (frm.TopMost)
{
frm.Text = "Your title";
}
}
Edit: Try this code. This will rename title of any windows process. I have used notepad and wordpad as example
private void button1_Click(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("notepad");
if (processes.Length > 0)
{
SetWindowText(processes[0].MainWindowHandle, "This is My Notepad");
// Renaming title of 1st notepad instance
//processes[0]
}
else
{
MessageBox.Show("Please start atleast one notepad instance..");
}
}
private void button2_Click(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("wordpad");
if (processes.Length > 0)
{
SetWindowText(processes[0].MainWindowHandle, "This is My wordpad");
// Renaming title of 1st notepad instance
//processes[0]
}
else
{
MessageBox.Show("Please start atleast one wordpad instance..");
}
}