sjehanzeb
asked on
problem with a control
i have an activex control like the
caption bar which i want to replace
by the orignal one
prablem is it wont change the position of the form when mouse is clicked and dragged
if you want the coding of the active x tool email me at saqibshakil@yifan.net
caption bar which i want to replace
by the orignal one
prablem is it wont change the position of the form when mouse is clicked and dragged
if you want the coding of the active x tool email me at saqibshakil@yifan.net
I guess you mean you are creating your own control which you want to use to replace the window's caption bar. You want to allow the user to move the form by clicking and dragging on this control - right ?
This article on vbnet should be exactly waht you need :
http://www.mvps.org/vbnet/code/neet/drawfocusrect.htm
This article on vbnet should be exactly waht you need :
http://www.mvps.org/vbnet/code/neet/drawfocusrect.htm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another API Solution.. (not as pretty as mcrider's tho.. <sigh>).. Followed by a TIP.. <smile>.
<----- Begin DECLARATIONS SECTION ----->
Private Type PointApi
X As Long
Y As Long
End Type
Private Declare Function ClientToScreen Lib "user32" _
(ByVal hwnd As Long, lpPoint As PointApi) _
As Long
Private Declare Function ReleaseCapture Lib "user32" _
() _
As Long
Private Declare Function SetCapture Lib "user32" _
(ByVal hwnd As Long) _
As Long
Private msngLastX As Single
Private msngLastY As Single
Private msngThisX As Single
Private msngThisY As Single
Private mudtPoint As PointApi
<----- End DECLARATIONS SECTION ----->
<----- Begin CODE SECTION ----->
Private Sub UserControl1_MouseDown(But ton As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton _
Then
Dim lngReturn As Long
lngReturn = SetCapture(UserControl1.hw nd)
mudtPoint.X = X / Screen.TwipsPerPixelX
mudtPoint.Y = Y / Screen.TwipsPerPixelY
lngReturn = ClientToScreen(UserControl 1.hwnd, mudtPoint)
msngLastX = mudtPoint.X * Screen.TwipsPerPixelX
msngLastY = mudtPoint.Y * Screen.TwipsPerPixelY
End If
End Sub
Private Sub UserControl1_MouseMove(But ton As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton _
Then
Dim lngReturn As Long
mudtPoint.X = X / Screen.TwipsPerPixelX
mudtPoint.Y = Y / Screen.TwipsPerPixelY
lngReturn = ClientToScreen(UserControl 1.hwnd, mudtPoint)
msngThisX = mudtPoint.X * Screen.TwipsPerPixelX
msngThisY = mudtPoint.Y * Screen.TwipsPerPixelY
Form1.Move _
Form1.Left + (msngThisX - msngLastX), _
Form1.Top + (msngThisY - msngLastY), _
Form1.Width, _
Form1.Height
msngLastX = msngThisX
msngLastY = msngThisY
End If
End Sub
Private Sub UserControl1_MouseUp(Butto n As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton _
Then
Dim lngReturn As Long
lngReturn = ReleaseCapture
End If
End Sub
<----- End CODE SECTION ----->
TIP: To get the Height of a standard Caption use the GetSystemMetricsInfo API..
Private Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) _
As Long
Private Const SM_CYCAPTION = 4 ' Height of caption or title
lngCaptionHeightExpressedI nPixels = _
GetSystemMetrics(SM_CYCAPT ION)
mcrider:
When you are not pretty.. you hasta work harder.. <smile> and a <wink>.. LOL.
<----- Begin DECLARATIONS SECTION ----->
Private Type PointApi
X As Long
Y As Long
End Type
Private Declare Function ClientToScreen Lib "user32" _
(ByVal hwnd As Long, lpPoint As PointApi) _
As Long
Private Declare Function ReleaseCapture Lib "user32" _
() _
As Long
Private Declare Function SetCapture Lib "user32" _
(ByVal hwnd As Long) _
As Long
Private msngLastX As Single
Private msngLastY As Single
Private msngThisX As Single
Private msngThisY As Single
Private mudtPoint As PointApi
<----- End DECLARATIONS SECTION ----->
<----- Begin CODE SECTION ----->
Private Sub UserControl1_MouseDown(But
If Button = vbLeftButton _
Then
Dim lngReturn As Long
lngReturn = SetCapture(UserControl1.hw
mudtPoint.X = X / Screen.TwipsPerPixelX
mudtPoint.Y = Y / Screen.TwipsPerPixelY
lngReturn = ClientToScreen(UserControl
msngLastX = mudtPoint.X * Screen.TwipsPerPixelX
msngLastY = mudtPoint.Y * Screen.TwipsPerPixelY
End If
End Sub
Private Sub UserControl1_MouseMove(But
If Button = vbLeftButton _
Then
Dim lngReturn As Long
mudtPoint.X = X / Screen.TwipsPerPixelX
mudtPoint.Y = Y / Screen.TwipsPerPixelY
lngReturn = ClientToScreen(UserControl
msngThisX = mudtPoint.X * Screen.TwipsPerPixelX
msngThisY = mudtPoint.Y * Screen.TwipsPerPixelY
Form1.Move _
Form1.Left + (msngThisX - msngLastX), _
Form1.Top + (msngThisY - msngLastY), _
Form1.Width, _
Form1.Height
msngLastX = msngThisX
msngLastY = msngThisY
End If
End Sub
Private Sub UserControl1_MouseUp(Butto
If Button = vbLeftButton _
Then
Dim lngReturn As Long
lngReturn = ReleaseCapture
End If
End Sub
<----- End CODE SECTION ----->
TIP: To get the Height of a standard Caption use the GetSystemMetricsInfo API..
Private Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) _
As Long
Private Const SM_CYCAPTION = 4 ' Height of caption or title
lngCaptionHeightExpressedI
GetSystemMetrics(SM_CYCAPT
mcrider:
When you are not pretty.. you hasta work harder.. <smile> and a <wink>.. LOL.
wsh2, That's ok... You've caught me more than once in my insomniac stupor ;-)
Can I ask why you graded this a "C"???
These can't be moved from their location at the bottom of the window.
If this isn't what you're talking about, post some code and the names of the controls you are using.