Results 1 to 4 of 4

Thread: change another window's size

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cochin, India
    Posts
    350

    Question change another window's size

    Can I change another window's width and height from my VB application If I know the caption on that window?
    Thanks
    DOK OCK : "The power of .net in the palm of my hand, nothing will stand in my way. Nothing."

  2. #2
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    Re: change another window's size

    Yes you can
    VB Code:
    1. ' Code on Form1
    2.   Form2.Show
    3.   Form2.Width = Form2.Width - 500
    4.   Form2.Height = Form2.Height - 500
    oh1mie/Vic


  3. #3
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    Re: change another window's size

    With caption name

    VB Code:
    1. ' Code on Form1
    2.     Dim strCaption As String
    3.     Dim MyObject   As Form
    4.    
    5.     Form2.Show
    6.     strCaption = "Form2"
    7.        
    8.     For Each MyObject In Forms
    9.         If MyObject.Name = strCaption Then
    10.            MyObject.Width = MyObject.Width - 500
    11.            MyObject.Height = MyObject.Height - 500
    12.            Exit For
    13.         End If
    14.     Next
    oh1mie/Vic


  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: change another window's size

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width