Link to home
Start Free TrialLog in
Avatar of sjehanzeb
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
Avatar of CoolAss
CoolAss

I am guessing you are talking about a status bar at the bottom of the dialog you are working on.

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.
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
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton _
    Then
        Dim lngReturn As Long
        lngReturn = SetCapture(UserControl1.hwnd)
        mudtPoint.X = X / Screen.TwipsPerPixelX
        mudtPoint.Y = Y / Screen.TwipsPerPixelY
        lngReturn = ClientToScreen(UserControl1.hwnd, mudtPoint)
        msngLastX = mudtPoint.X * Screen.TwipsPerPixelX
        msngLastY = mudtPoint.Y * Screen.TwipsPerPixelY
    End If
End Sub

Private Sub UserControl1_MouseMove(Button 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(UserControl1.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(Button 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

lngCaptionHeightExpressedInPixels = _
    GetSystemMetrics(SM_CYCAPTION)

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"???