Can I change another window's width and height from my VB application If I know the caption on that window?
Thanks
Printable View
Can I change another window's width and height from my VB application If I know the caption on that window?
Thanks
Yes you can
VB Code:
' Code on Form1 Form2.Show Form2.Width = Form2.Width - 500 Form2.Height = Form2.Height - 500
With caption name
VB Code:
' Code on Form1 Dim strCaption As String Dim MyObject As Form Form2.Show strCaption = "Form2" For Each MyObject In Forms If MyObject.Name = strCaption Then MyObject.Width = MyObject.Width - 500 MyObject.Height = MyObject.Height - 500 Exit For End If Next
If you want to change the size of a external applications window then:
If you only know the caption (not the class) then you'll have to enumerate through the windows using EnumWindows, and check the window caption using GetWindowText, until you find the right one.
If you know the window class as well as the caption then you can use FindWindow to get the handle.
Once you've got the handle of the window you can use SetWindowPlacement or MoveWindow (and there are probably others) to change the windows position and size.