Results 1 to 11 of 11

Thread: Setting a Button location !!!!

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    43

    Setting a Button location !!!!

    How do I set/change the location of a Button located within its Parent Window via the API ?

    I can easily set the position of a Parent Window via the SetWindowPos or MoveWindow APIs but I can't make it work for a child window (ie Button)

    I have used many other supporting functions in the process like GetWindowRect, ClientToScreen... but with no luck

    Anyone has an answer out there ?

    Thanks.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Setting a Button location !!!!

    Moved from CodeBank

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    43

    Re: Setting a Button location !!!!

    Sorry moved where ?

    Thanks.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Setting a Button location !!!!

    Quote Originally Posted by BLUE_SEA
    Sorry moved where ?

    Thanks.
    Here...the ClassicVB section.

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

    Re: Setting a Button location !!!!

    I had no trouble using moving a button in calculator. What are you trying to move and what code have you tried so far?

    VB Code:
    1. Private Declare Function MoveWindow Lib "user32" ( _
    2.                 ByVal hwnd As Long, _
    3.                 ByVal x As Long, _
    4.                 ByVal y As Long, _
    5.                 ByVal nWidth As Long, _
    6.                 ByVal nHeight As Long, _
    7.                 ByVal bRepaint As Long) As Long
    8.                
    9. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    10.                 ByVal lpClassName As String, _
    11.                 ByVal lpWindowName As String) As Long
    12.                
    13. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    14.                 ByVal hWnd1 As Long, _
    15.                 ByVal hWnd2 As Long, _
    16.                 ByVal lpsz1 As String, _
    17.                 ByVal lpsz2 As String) As Long
    18.  
    19. Private Sub Command1_Click()
    20.     Dim lHwnd As Long
    21.     Dim lHwndChild As Long
    22.    
    23.     lHwnd = FindWindow(vbNullString, "Calculator")
    24.     lHwndChild = FindWindowEx(lHwnd, 0&, "Button", "Backspace")
    25.     MoveWindow lHwndChild, 0, 0, 100, 100, True
    26. End Sub

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    43

    Re: Setting a Button location !!!!

    Thanks bushmobile,

    I want to move the OK button when I resize the Standard VB InputBox so if for example I change the width of the InputBox Window the Ok Button should then move so that it stays always at the same distance from the InpuBox right border .

    Any Idea ?

    Thanks.

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

    Re: Setting a Button location !!!!

    If this is your app, then the easiest thing to do is create your own InputBox. I've attached an example:

    Attached Files Attached Files

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    43

    Re: Setting a Button location !!!!

    Quote Originally Posted by bushmobile
    If this is your app, then the easiest thing to do is create your own InputBox. I've attached an example:
    Thanks again but this Custom InputBox doesn't have the option to change its own size . I specifically want to be able to resize it and for the OK and Cancel buttons to remain in the same location in relation to the inputbox right border.

    Any thoughts ?

    Thank you.
    Last edited by BLUE_SEA; Apr 4th, 2006 at 03:35 AM.

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

    Re: Setting a Button location !!!!

    that custom input box was just an example. It's a form that you have full control over (rather the the normal inputbox that you don't). Just resize/reposition your controls in the Form_Resize event.

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    43

    Re: Setting a Button location !!!!

    Thanks,

    I really need to get this working with the standard VB InputBox not with a userform as I am doing this for educational purposes.

    Any chance anyone ??

    BLUE_SEA

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

    Re: Setting a Button location !!!!

    Here's some threads about customising the standard MessageBox (same principle will apply for the InputBox):

    http://www.vbforums.com/showpost.php...58&postcount=4
    http://www.vbforums.com/showthread.php?t=329373

    As you can see, it ain't easy.

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