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 :blush:
Anyone has an answer out there ? :wave:
Thanks.
Re: Setting a Button location !!!!
Re: Setting a Button location !!!!
Sorry moved where ?
Thanks.
Re: Setting a Button location !!!!
Quote:
Originally Posted by BLUE_SEA
Sorry moved where ?
Thanks.
Here...the ClassicVB section.
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:
Private Declare Function MoveWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Sub Command1_Click()
Dim lHwnd As Long
Dim lHwndChild As Long
lHwnd = FindWindow(vbNullString, "Calculator")
lHwndChild = FindWindowEx(lHwnd, 0&, "Button", "Backspace")
MoveWindow lHwndChild, 0, 0, 100, 100, True
End Sub
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.
1 Attachment(s)
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:
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.
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.
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 ?? :wave:
BLUE_SEA
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.