Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call window to new monitor

Status
Not open for further replies.

Fullmetal99012

Programmer
Feb 15, 2010
4
US
thread732-1416749 I would like to make an application with a function similar to this thread. I want the user to beable to start a process, and have it call the window of the process to the same screen the form is on. the program already calls the form to a secondary monitor if available.

I also want it to do the same for a 3rd or 4th monitor.

(I.E - a user has a shortcut on my form, they click it, and it opens the process and moves the window to the monitor that the form is on).
 
While I am asking the first question. i might as well ask my socend problem as well. I have seen two functions GetMonitorBrightness() and SetMonitorBrightness(). Does anyone know how to use them. If not, dont worry about it. Its not as important as my main problem.
 
Is this what you are after?
Code:
        private void Monitor1Button_Click(object sender, EventArgs e)
        {
            MoveToMonitor(1);
        }

        private void Monitor2Button_Click(object sender, EventArgs e)
        {
            MoveToMonitor(2);
        }

        private void MoveToMonitor(int index)
        {
            index--;
            Screen[] sc;
            sc = Screen.AllScreens;
            this.Left = sc[index].Bounds.Width;
            this.Top = sc[index].Bounds.Height;
            this.Location = sc[index].Bounds.Location;
            Point p = new Point(sc[index].Bounds.Location.X, sc[index].Bounds.Location.Y);
            this.Location = p;
        }
 
Not exactly. I need to satrt a process (Firefox.exe). and then move it to the same monitor that the form is on. (I.E form is on monitor 2, firefox window goes to monitor 2, form is on monitor 3, firefox goes to monitor 3).
 
Ah I see. Well I've got this code, it's not mine and can't remember where I got if from but I think it will help you.

Code:
[DllImport("user32.dll", EntryPoint = "SetWindowPos")] 
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags); 

const short SWP_NOMOVE = 0X2; 
const short SWP_NOSIZE = 1; 
const short SWP_NOZORDER = 0X4; 
const int SWP_SHOWWINDOW = 0x0040; 
 
public static void Move(var process) 
{ 
    var handle = process.MainWindowHandle; 
    var form = Control.FromHandle(handle); 
 
    SetWindowPos(handle, 0, 0, 0, form.Bounds.Width, form.Bounds.Height, SWP_NOZORDER | SWP_SHOWWINDOW); 
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top