Hey guys. I have a question. In my program, I'm calling a Process (Internet Explorer) on button click, but I want to customize the size of the IE window being opened to something like 800 x 600 pixels. Do you know how do it? Below is my base code.

Process p = new Process();
p.StartInfo.FileName = "IExplore.exe";
p.StartInfo.Arguments = target; //target is a string -- this is the link that I'm opening
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.Start();

I know I have to use API. I tried to use below code, but the window is not resizing. What happens is it sticks to the previous location and size of the previous internet explorer that I executed. Say I opened an IE, resized it manually to 300 x 300. The next time I click the button and call my functions to resize, it still opens the 300 x 300 that I left.

IntPtr hWnd = (IntPtr) p.MainWindowHandle.ToInt64();
RECT rect = new RECT(new Point(500, 500), new Size(800, 600));
GetWindowRect(hWnd, out rect);
int width = rect.Right - rect.Left;
int height = rect.Bottom - rect.Top;
MoveWindow(hWnd, rect.Left, rect.Top, width, height, true);

Thanks a lot!

Try the code sample at this page as it seems to do exactly what you want.

Seems to be a combination of C# and JavaScript coding to accomplish the effect.

Hope this helps :) Mark as solved if it does.

Edit: As a side note, the above sample appears to be for a web-app deployment, if you're working on a windows forms app then the sample may not work the same in a non-browser environment.

thanks for the answer. but i'm working for a Windows Application, so it's not applicable. :)

Yes and no... You're working on a windows application but you're calling your process in a browser which is why I figure that this *might* just work. Couldn't hurt to give it a try, no? :P

Another resource to look at (if you haven't already) is at this page.

Shows the use of the InternetExplorer object class which has adjustable properties including height and width.

Another resource to look at (if you haven't already) is at this page.

Shows the use of the InternetExplorer object class which has adjustable properties including height and width.

hey dude. thanks a lot! this helped me solve my problem. this is what I'm looking for. you're amazing! :icon_cheesygrin:

i just used the Height and Width properties.

SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
object Empty = 0;
object URL = target; //the link that I'm going to open

IE.Visible = true;
IE.Width = 800;
IE.Height = 600;
IE.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);
System.Threading.Thread.Sleep(5000);

Glad I could help :) Don't forget to mark solved so others don't think the issue is still unresolved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.